seth87 Posted June 5, 2010 Share Posted June 5, 2010 Hi all im new here I am having an issue with pagination. Im making a search where you can search for video games. There is a form with 2 select boxes where users can select a 'genre' and a 'console'. The results are returned and displayed correctly. Im trying to display 2 results per page(it will get bigger eventually) then the user has to click next to see the following two. However, when you select to go to the next page, nothing is displayed. The pagination works correctly but the details from the database dont display. In the SQL query, if you enter the genre and console manually it works perfectly. But when these details are coming from the select boxes through $_POST, it stops working. Below is my code, any help will be greatly appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styles/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="main"> <form action="search.php" method="post"> <label for="genre">Genre</label> <select id="genre" name="genre"> <option value="">--Any--</option> <option value="action">Action</option> <option value="adventure">adventure</option> <option value="fighting">Fighting</option> <option value="shooter">Shooter</option> <option value="rpg">RPG</option> <option value="platform">Platform</option> <option value="party">Party</option> <option value="sport">Sport</option> <option value="racing">Racing</option> </select> <label for="console">Console</label> <select id="console" name="console"> <option value="">--Any--</option> <option value="ps3">ps3</option> <option value="xbox360">XBOX360</option> <option value="wii">WII</option> </select> <input type="submit" name="submit" id="submit" value="Search" /> </form> <table id="displaytable"> <tr><th>Name</th><th>Price</th><th>Genre</th><th>Console</th><th>Image</th></tr> <?php $post_genre = $_POST['genre']; //get genre from select box $post_console = $_POST['console']; //get console from select box $connect = mysql_connect("localhost","root","") or die("Could not connect to database"); mysql_select_db("pagination") or die (mysql_error()); $per_page = 2; //results to be display per page $start = $_GET['start']; //get variable $howmany = mysql_num_rows(mysql_query("SELECT * FROM data WHERE genre LIKE '$post_genre' AND console LIKE '$post_console'")); //num of results if (!$start) $start = 0; $getresult = mysql_query("SELECT * FROM data WHERE genre='$post_genre' AND console = '$post_console' LIMIT $start, $per_page"); //results with limit // display the results while ($row = mysql_fetch_assoc($getresult)) { ?> <tr><td><?php echo $name = $row['name'];?></td> <td><?php echo "$" . $price = $row['price'];?></td> <td><?php echo $genre = $row['genre'];?></td> <td><?php echo $console = $row['console'];?></td> <td><img src="<?php echo $imglocation = $row['imglocation'];?>" alt="" /></td></tr> <?php }?> </table> <?php $prev = $start - $per_page; $next = $start + $per_page; //prev link if (!($start<=0)) echo "<a href='search.php?start=$prev'>Prev</a>"; $page_no = 1; //first page will display 1 for ($x=0; $x<$howmany; $x= $x + $per_page) { if ($start!=$x) echo " <a href='search.php?start=$x'>$page_no</a> "; else echo " <a href='search.php?start=$x'><b>$page_no</b></a> "; $page_no++; } //next link if (!($start>=$howmany-$per_page)) echo "<a href='search.php?start=$next'>Next</a>"; ?> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/203957-pagination-issues-with-form/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.