wannabeeaweak 0 Report post Posted September 23, 2005 (edited) this is the original script i made <?php# include file include ("connect.php"); $db=mysql_select_db(unknow,$connection);$sql="SELECT id, Game_name, Game_link, Game_image ,Game_from FROM `Games` ORDER BY id";$mysql_result=mysql_query($sql);$num_rows=mysql_num_rows($mysql_result);if ( $num_rows == 0){ echo "Sorry there is no information in that database please come back later";}else {# we have result#create tableWHILE ($row=mysql_fetch_array($mysql_result)){ $id=$row["id"]; $Game_name=$row["Game_name"]; $Game_link=$row["Game_link"]; $Game_image=$row["Game_image"]; echo "<table bgcolor=\"#666666\" align=\"center\">"; echo "<tr><td bgcolor=\"#666666\"><div align=\"center\">"; echo "<table width=\"376\" bgcolor=\"black\" align=\"center\">"; echo "<tr><td width=\"98\" rowspan=\"0\"><img src=\"$Game_image\" width=\"65\" height=\"65\"><br><span class=\"style3\">$Game_name</span></td>"; echo "<td height=\"91\" colspan=\"3\"><span class=\"style3\">$Game_description</span></td></tr>"; echo "<tr><td width=\"130\"><div align=\"center\"><span class=\"style1\"><a href=\"play_game.php?row_id=$id\">Play Game</a></span></div></td>"; echo "<td width=\"264\"><div align=\"center\"><form name=\"rate_game\"> <select name=\"rate_game\" onChange=\"MM_jumpMenu('parent',this,1)\"> <option selected>Rate Game</option> <option value=\"rating_game.php?id=$id,rating=1\">1</option> <option value=\"rating_game.php?id=$id,rating=2\">2</option> <option value=\"rating_game.php?id=$id,rating=3\">3</option> <option value=\"rating_game.php?id=$id,rating=4\">4</option> <option value=\"rating_game.php?id=$id,rating=5\">5</option> <option value=\"rating_game.php?id=$id,rating=6\">6</option> <option value=\"rating_game.php?id=$id,rating=7\">7</option> <option value=\"rating_game.php?id=$id,rating=8\">8</option> <option value=\"rating_game.php?id=$id,rating=9\">9</option> <option value=\"rating_game.php?id=$id,rating=10\">10</option> </select> </form></div></td>"; echo "<td width=\"0\" height=\"28\"><div align=\"center\"><span class=\"style3\"></span></div></td></tr>"; echo "</table></div></div></td></tr></table>";}} # end elsemysql_close($connection); ?> and i wanted to add a next page function on it and this is what i came up with <?php# include file include ("connect.php"); $db=mysql_select_db(unknow,$connection);$per_page = 7;$sql="SELECT id, Game_name, Game_link, Game_image ,Game_from FROM `Games` ORDER BY id";// Set page #, if no page isspecified, assume page 1if (!$page) { $page = 1;}$prev_page = $page - 1;$next_page = $page + 1;$mysql_result=mysql_query($sql);// Set up specified page$page_start = ($per_page * $page) - $per_page;$num_rows = mysql_num_rows($mysql_result);if ($num_rows <= $per_page) { $num_pages = 1;} else if (($num_rows % $per_page) == 0) { $num_pages = ($num_rows / $per_page);} else { $num_pages = ($num_rows / $per_page) + 1;}$num_pages = (int) $num_pages;if (($page > $num_pages) || ($page < 0)) { error("You have specified an invalid page number");}$sql = $sql . " LIMIT $page_start, $per_page";while ($result = mysql_fetch_array($mysql_result)){ $id=$row["id"]; $Game_name=$row["Game_name"]; $Game_link=$row["Game_link"]; $Game_image=$row["Game_image"]; echo "<table bgcolor=\"#666666\" align=\"center\">"; echo "<tr><td bgcolor=\"#666666\"><div align=\"center\">"; echo "<table width=\"376\" bgcolor=\"black\" align=\"center\">"; echo "<tr><td width=\"98\" rowspan=\"0\"><img src=\"$Game_image\" width=\"65\" height=\"65\"><br><span class=\"style3\">$Game_name</span></td>"; echo "<td height=\"91\" colspan=\"3\"><span class=\"style3\">$Game_description</span></td></tr>"; echo "<tr><td width=\"130\"><div align=\"center\"><span class=\"style1\"><a href=\"play_game.php?row_id=$id\">Play Game</a></span></div></td>"; echo "<td width=\"264\"><div align=\"center\"><form name=\"rate_game\"> <select name=\"rate_game\" onChange=\"MM_jumpMenu('parent',this,1)\"> <option selected>Rate Game</option> <option value=\"rating_game.php?id=$id,rating=1\">1</option> <option value=\"rating_game.php?id=$id,rating=2\">2</option> <option value=\"rating_game.php?id=$id,rating=3\">3</option> <option value=\"rating_game.php?id=$id,rating=4\">4</option> <option value=\"rating_game.php?id=$id,rating=5\">5</option> <option value=\"rating_game.php?id=$id,rating=6\">6</option> <option value=\"rating_game.php?id=$id,rating=7\">7</option> <option value=\"rating_game.php?id=$id,rating=8\">8</option> <option value=\"rating_game.php?id=$id,rating=9\">9</option> <option value=\"rating_game.php?id=$id,rating=10\">10</option> </select> </form></div></td>"; echo "<td width=\"0\" height=\"28\"><div align=\"center\"><span class=\"style3\"></span></div></td></tr>"; echo "</table></div></div></td></tr></table>";}if ($prev_page) { echo "<a href=\"index2.php?page=$prev_page\">Prev</a>}for ($i = 1; $i <= $num_pages; $i++) { if ($i != $page) { echo "<a href=\"index2.php?page=$i\">$i</a>"; } else { echo " $i "; }}// Nextif ($page != $num_pages) { echo "<a href=\"index2.php?page=$next_page\">Next</a>}# we have result#create table} # end elsemysql_close($connection); ?> and it doesn't work can any one help i want to add a next page funstion to this script so i can display only 7 per page. so can any one help or give me some example or something to make my script better? Edited September 23, 2005 by moonwitch (see edit history) Share this post Link to post Share on other sites
Spectre1405241486 0 Report post Posted September 24, 2005 You could try storing somewhere (in a hidden POST field or as a GET variable, it doesn't matter) the ID of the last entry displayed, and then only display the next 7 entries after that. Note that although you could calculate the next ID by multiplying the 'per_page' value by the current page, that probably wouldn't be a good idea - if a number was skipped at all in the 'id' field, it wouldn't work. You could try something like this: $last_id = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;$sql='SELECT id, Game_name, Game_link, Game_image ,Game_from FROM `Games` WHERE id >= ' . $last_id . ' ORDER BY id LIMIT ' . $per_page;...// This is AFTER the while() statement - the current $result array will contain the last entry retrieved$last_id = $result['id'];// Nextif ($page != $num_pages) { echo "<a href=\"index2.php?page=$next_page&id=$last_id\">Next</a>} Share this post Link to post Share on other sites
wannabeeaweak 0 Report post Posted September 24, 2005 thanks for the help but i am looking to just have a next page and pervious page and only have 7 games a page and well i need help to make this code work You could try storing somewhere (in a hidden POST field or as a GET variable, it doesn't matter) the ID of the last entry displayed, and then only display the next 7 entries after that. Note that although you could calculate the next ID by multiplying the 'per_page' value by the current page, that probably wouldn't be a good idea - if a number was skipped at all in the 'id' field, it wouldn't work. You could try something like this: $last_id = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;$sql='SELECT id, Game_name, Game_link, Game_image ,Game_from FROM `Games` WHERE id >= ' . $last_id . ' ORDER BY id LIMIT ' . $per_page;...// This is AFTER the while() statement - the current $result array will contain the last entry retrieved$last_id = $result['id'];// Nextif ($page != $num_pages) { echo "<a href=\"index2.php?page=$next_page&id=$last_id\">Next</a>} 1064323536[/snapback] Share this post Link to post Share on other sites