doforumda Posted October 18, 2009 Share Posted October 18, 2009 hi i create a pagination and its code is down below <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php mysql_connect("localhost"); mysql_select_db("test"); $per_page = 5; $start = $_GET['start']; $record_count = mysql_num_rows(mysql_query("select * from data")); $max_pages = $record_count/$per_page; if(!$start) $start = 0; $get = mysql_query("select * from data limit $start, $per_page"); while($row=mysql_fetch_assoc($get)) { $name = $row['name']; $age = $row['age']; echo $name." (".$age.")<br>"; } $prev = $start - $per_page; $next = $start + $per_page; if(!($start<=0)) echo "<a href='pagination.php?start=$prev'>Prev</a> "; $i=1; for($x=0;$x<$record_count;$x=$x+$per_page) { if($start!=$x) echo " <a href='pagination.php?start=$x'>$i</a> "; else echo " <a href='pagination.php?start=$x'><b>$i</b></a> "; $i++; } if(!($start>=$record_count-$per_page)) echo " <a href='pagination.php?start=$next'>Next</a>"; ?> </body> </html> problem in this code is when i load this page first time then it displays this error Notice: Undefined index: start in D:\wamp\www\examples\pagination.php on line 14 but when i click next or prev buttons then it works fine. how this can be solved? Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/ Share on other sites More sharing options...
Kaboom Posted October 18, 2009 Share Posted October 18, 2009 hi i create a pagination and its code is down below <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php mysql_connect("localhost"); mysql_select_db("test"); $per_page = 5; $start = $_GET['start']; $record_count = mysql_num_rows(mysql_query("select * from data")); $max_pages = $record_count/$per_page; if(!$start) $start = 0; $get = mysql_query("select * from data limit $start, $per_page"); while($row=mysql_fetch_assoc($get)) { $name = $row['name']; $age = $row['age']; echo $name." (".$age.")<br>"; } $prev = $start - $per_page; $next = $start + $per_page; if(!($start<=0)) echo "<a href='pagination.php?start=$prev'>Prev</a> "; $i=1; for($x=0;$x<$record_count;$x=$x+$per_page) { if($start!=$x) echo " <a href='pagination.php?start=$x'>$i</a> "; else echo " <a href='pagination.php?start=$x'><b>$i</b></a> "; $i++; } if(!($start>=$record_count-$per_page)) echo " <a href='pagination.php?start=$next'>Next</a>"; ?> </body> </html> problem in this code is when i load this page first time then it displays this error Notice: Undefined index: start in D:\wamp\www\examples\pagination.php on line 14 but when i click next or prev buttons then it works fine. how this can be solved? Your error is here $start = $_GET['start']; Change start to index.php or something? Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-939012 Share on other sites More sharing options...
doforumda Posted October 18, 2009 Author Share Posted October 18, 2009 still not working. the same error Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-939014 Share on other sites More sharing options...
.josh Posted October 18, 2009 Share Posted October 18, 2009 $start = $_GET['start']; problem is first time around there isn't a value for $_GET['start'] so it's undefined. You can get rid of it by assigning a default to $start if $_GET['start'] doesn't exist: $start = ($_GET['start'])? $_GET['start'] : '1'; Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-939021 Share on other sites More sharing options...
doforumda Posted October 18, 2009 Author Share Posted October 18, 2009 Crayon Violent this also is not working same error Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-939033 Share on other sites More sharing options...
doforumda Posted October 18, 2009 Author Share Posted October 18, 2009 anyone who can help i am still waiting Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-939083 Share on other sites More sharing options...
.josh Posted October 18, 2009 Share Posted October 18, 2009 you are getting the exact same error on the exact same line? Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-939177 Share on other sites More sharing options...
Kaboom Posted June 29, 2010 Share Posted June 29, 2010 Just noticed, so something like if ($start == "") { $start = "1"; } so if it's empty set it to one Quote Link to comment https://forums.phpfreaks.com/topic/178086-need-help-in-pagination/#findComment-1078622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.