rallokkcaz Posted May 5, 2007 Share Posted May 5, 2007 how would i make it so when i grab info from the data base, instead of it making one long page of info it spreads it into different pages <?php include 'header.php'; //connect to and select db $conn = mysql_connect('localhost','username','password') or die(mysql_error()); $db = mysql_select_db('pokebash_users',$conn) or die(mysql_error()); //get a list of the info from the table to make the linkies $sql = "select * from news ORDER BY id desc"; $result = mysql_query($sql, $conn) or die(mysql_error()); // for each row fetched from the results... while ($list = mysql_fetch_array($result)) { //make the custom linkie echo " <fieldset style='padding:5px; width:500px;'> <legend>"; echo $list['topic'] ; echo " "; echo "Posted at: "; echo $list['time'] ; echo " </legend> <table cellpadding='10px'> <tr> <td> "; echo $list['content'] ; echo " </td> </tr> </table> </fieldset><br> <a href='http://www.getmetola.com/post.php?id={$list['id']}'>View Topic</a> <br> <br> "; } // end while // if the user clicked on a linkie and therefore an id exists (the is_numeric is a basic security precaution) ... if (is_numeric($_GET['id'])) { // for easier var syntax handling $id = $_GET['id']; $sql = "select topic from news where id = '$id'"; $result = mysql_query($sql, $conn) or die(mysql_error()); $userfound = mysql_num_rows($result); if ($userfound) { $user = mysql_fetch_array($result); } // end if found } // end if there was a linkie clicked ?> does anyone know how to do that??? Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 Use Limit X,Y <?php $page = $_GET['page']; // page number $X = ($page - 1); $Y = (10 * $page); $sql = "select * from news ORDER BY id desc Limit $X,$Y "; ?> Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/#findComment-246172 Share on other sites More sharing options...
rallokkcaz Posted May 5, 2007 Author Share Posted May 5, 2007 now i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1,0' at line 1 here is the code <?php include 'header.php'; //connect to and select db $conn = mysql_connect('localhost','username','password') or die(mysql_error()); $db = mysql_select_db('pokebash_users',$conn) or die(mysql_error()); //get a list of the info from the table to make the linkies $page = $_GET['page']; // page number $X = ($page - 1); $Y = (5 * $page); $sql = "select * from news ORDER BY id desc Limit $X,$Y "; $result = mysql_query($sql, $conn) or die(mysql_error()); // for each row fetched from the results... while ($list = mysql_fetch_array($result)) { //make the custom linkie echo " <fieldset style='padding:5px; width:500px;'> <legend>"; echo $list['topic'] ; echo " "; echo "Posted at: "; echo $list['time'] ; echo " </legend> <table cellpadding='10px'> <tr> <td> "; echo $list['content'] ; echo " </td> </tr> </table> </fieldset><br> <a href='http://www.getmetola.com/post.php?id={$list['id']}'>View Topic</a> <br> <br> "; } // end while // if the user clicked on a linkie and therefore an id exists (the is_numeric is a basic security precaution) ... if (is_numeric($_GET['id'])) { // for easier var syntax handling $id = $_GET['id']; $sql = "select topic from news where id = '$id'"; $result = mysql_query($sql, $conn) or die(mysql_error()); $userfound = mysql_num_rows($result); if ($userfound) { $user = mysql_fetch_array($result); } // end if found } // end if there was a linkie clicked ?> Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/#findComment-246177 Share on other sites More sharing options...
rallokkcaz Posted May 5, 2007 Author Share Posted May 5, 2007 anyone Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/#findComment-246184 Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 it was just an example <?php //get a list of the info from the table to make the linkies $page = (isset($_GET['page']))?$_GET['page']:1; // page number $X = ($page - 1); $Y = (5 * $page); $sql = "select * from news ORDER BY id desc Limit $X,$Y "; $result = mysql_query($sql, $conn) or die(mysql_error()); ?> would probably be better, i assume your calling the page like so myscript.php?page=1 Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/#findComment-246188 Share on other sites More sharing options...
rallokkcaz Posted May 5, 2007 Author Share Posted May 5, 2007 so how would i make it show it shows links on the bottom and top of the page for pages? Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/#findComment-246193 Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 look for a Pagination, it will be simpler.. as for adding a link <a href="myscript.php?page=($page+1)">Next Page</a> Link to comment https://forums.phpfreaks.com/topic/50143-how-to-make-paged-viewing-for-retrived-data/#findComment-246196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.