/    Sign up×
Community /Pin to ProfileBookmark

help with to divide database news to pages

hi everyone
i want to build pagination with PHP but i cannot
for ex i have 100 number of news and i like my page show only 10 news per page so let it displays 10 page and below let it is written
page1, page2, page3, and whenever i want to click on this pages let it goes the page which is clicked
this my database sql.

[CODE]CREATE TABLE `news` (
id int(11) NOT NULL auto_increment,
theme varchar(200) NOT NULL default ”,
author varchar(100) NOT NULL default ”,
date date NOT NULL default ‘0000-00-00’,
text text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
[/CODE]

i did like this but it doesnt work

[CODE]<?

@$db=mysql_connect(‘localhost’,’username’,’parol’);
mysql_select_db(‘db_name’);

$per_page=10;

$q=”SELECT count(*) FROM `news`”;
$res=mysql_query($q);
$row=mysql_fetch_row($res);
$total_rows=$row[0];
$num_pages=ceil($total_rows/$per_page);

echo ‘<h1>news</h1>’;
$sql=”SELECT * FROM `news` “;
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
for ($i=0; $i<$num_results; $i++)
{
$row=mysql_fetch_array($result);

$id=$row[“id”];
$author=$row[“author”];
$date=$row[“date”];
$tema=$row[“tema”];
$text=$row[“text”];

echo ‘<b>’.$theme.'</b><br>

<a href=”/news/’.$id.’/”>added by</a>: <b>’.$author.'</b>

(‘.$date.’)<p> ‘.$text.’ <hr>’;
}

[/CODE]

i need this script
if possible pls see it
Thanks for attention

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@dk_zero-coolFeb 28.2010 — http://www.webgeek.eu/?l=/en/archive/25

This will take care of everything for you.
×

Success!

Help @azegurb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...