Guest D1proball Posted March 24, 2006 Share Posted March 24, 2006 Ok so I almost have my search ready and to test it out I made it so the results only print 1 result per page. I know that I have 18 objects in my database so the number of pages should read 18, which it does. However, when I click on a link to go to the next result it says, Error: Query was empty. Heres the url to my site to see what I'm talking about.. [a href=\"http://www.acadvocates.com/work2.php\" target=\"_blank\"]http://www.acadvocates.com/work2.php[/a] Here's the code. [code]<?php // The first function connects to your database, the second selects a database include"connect.php"; ?> <br><table width="60%" height="1%" border="1" align="center" bordercolor="#003300"> <tr> <td height="27" bgcolor="B5F2B5"><form name="form1" method="post" action=""> <div align="center">Search: <select name="searchtype" id="searchtype"> <option selected>Name</option> <option>Species</option> <option>Personality</option> </select> <input name="search" type="text" id="search"> <input name="submit" type="submit" id="submit" value="Search"> </div> </form></td> </tr> <tr> <td height="28" bgcolor="B5F2B5"> <form name="form2" method="post" action=""> <div align="center">Sort: <select name="sorttype" id="sorttype"> <option selected>Name</option> <option>Species</option> <option>Personality</option> </select> <select name="sortorder" id="sortorder"> <option selected>Ascending</option> <option>Descending</option> </select> <input name="submit2" type="submit" id="submit2" value="Sort"> </div> </form></td> </tr></table><br><?$searchtype=$_POST['searchtype'];$search=$_POST['search'];$sorttype=$_POST['sorttype'];$sortorder=$_POST['sortorder'];$searchtype2=$_GET['searchtype'];$search2=$_GET['search'];$sorttype2=$_GET['sorttype'];$sortorder2=$_GET['sortorder'];if($sortorder=="Descending"){ $sort="desc";} else{$sort=""; }if(isset($searchtype)){ $query = "SELECT * FROM neighbor where name like '%$search%' ORDER BY 'name' ";}elseif(isset($sorttype)){ $query = "SELECT * FROM neighbor ORDER BY $sorttype $sort ";}elseif(isset($searchtype2)){ $query = "SELECT * FROM neighbor where name like '%$search2%' ORDER BY 'name' ";}elseif(isset($sorttype2)){ $query = "SELECT * FROM neighbor ORDER BY $sorttype2 $sort "; } /* Tip: The @ in front of these two functions will hide the username andpassword if there is an error. The die() function will kill the script and showan error statement if something goes wrong with the connect or select functions.A mysql_connect() error usually means your username/password are wrong, and amysql_select_db() error usually means the database doesn't exist. */$limit = 1; // Sets how many results shown per page $query_count = $query; // Sets what we want to pull from the database // count(*) is better for large databases (thanks Greg!) $result_count = mysql_query($query_count); // Pulls what we want from the database $totalrows = mysql_num_rows($result_count); // This counts the number of users if(empty($page)){ // Checks if the $page variable is empty (not set) $page = 1; // If it is empty, we're on page 1 } $limitvalue = $page * $limit - ($limit); // Ex: (2 * 25) - 25 = 25 <- data starts at 25if(isset($searchtype)){ $query1 = "SELECT * FROM neighbor where name like '%$search%' ORDER BY 'name' LIMIT $limitvalue, $limit ";}elseif(isset($sorttype)){ $query1 = "SELECT * FROM neighbor ORDER BY $sorttype $sort LIMIT $limitvalue, $limit ";}elseif(isset($searchtype2)){ $query1 = "SELECT * FROM neighbor where name like '%$search2%' ORDER BY 'name' LIMIT $limitvalue, $limit ";}elseif(isset($sorttype2)){ $query1 = "SELECT * FROM neighbor ORDER BY $sorttype2 $sort LIMIT $limitvalue, $limit ";} print"$sorttype"; $result = mysql_query($query1) or die("Error: " . mysql_error()); // Selects all the data from table. // mysql_error() will print an error if one occurs. /* Tip: The MySQL LIMIT value syntax is as follows: LIMIT $row_to_start_at, $how_many_rows_to_return */if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } // This reads the number of rows returned // from the result above. /* Tip: You could probably use if($totalrows == 0) for the if statement;however, reading the actual $result from the data you'll be printing to thescreen is more accurate, and is a surefire way of preventing certain errors. */$bgcolor = "#E0E0E0"; // light gray /* Sets up one of the background colors. The color stated here will bedisplayed second */ echo("<table>"); // Just a simple table while($row = mysql_fetch_array($result)){ print"<center><table width=\"40%\" border=\"1\" bordercolor=\"#006600\" bgcolor=\"#FFFFFF\"> <tr> <td height=\"108\"><p align=\"center\"><img src=\"http://www.acadvocates.com/images/neighbors/$row[image]\" width=\"95\" height=\"85\" align=\"middle\"> <br><center><b>$row[Name]</b></center></td> </tr> <tr> <td height=\"164\"><table width=\"100%\" height=\"157\" border=\"0\" bordercolor=\"#006600\"> <tr> <td width=\"40%\" height=\"11\"><strong><font size=\"-1\">Species</font></strong></td> <td width=\"60%\"><font size=\"-1\">$row[Species]</font></td> </tr> <tr> <td height=\"11\"><strong><font size=\"-1\">Birthday</font></strong></td> <td height=\"11\"><font size=\"-1\">$row[Bday]</font></td> </tr> <tr> <td height=\"24\"><strong><font size=\"-1\">Gender</font></strong></td> <td height=\"24\"><font size=\"-1\">$row[Gender]</font></td> </tr> <tr> <td height=\"24\"><strong><font size=\"-1\">Personality</font></strong></td> <td height=\"24\"><font size=\"-1\">$row[Personality]</font></td> </tr> <tr> <td height=\"24\"><strong><font size=\"-1\">Catchphrase</font></strong></td> <td height=\"24\"><font size=\"-1\">$row[Catchphrase]</font></td> </tr> <tr> <td height=\"23\"><strong><font size=\"-1\">Picture Phrase</font></strong></td> <td height=\"23\"><font size=\"-1\">$row[Picphrase]</font></td> </tr> </table></td> </tr></table><br></center>"; } /* This closes the loop. Anything after this bracket will display after thedata you've pulled from the database. */ echo("</table>"); $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result);?>[/code] Quote Link to comment Share on other sites More sharing options...
JonathanAnon Posted March 24, 2006 Share Posted March 24, 2006 Hi, there's a lot of code there. Can I suggest two things first. 1. echo out the SQL statement before the query is run. See that the all the variables are being passed and that the query is being created correctly. You could us phpmyadmin to run this sql statement on the database and make sure that there is not any syntax errors with it. 2. make sure that the connect.php file is okay. also, I use:include('connect.php'); as the code for my includes. I'm not sure if you're way works aswell. It may do but test it out. Maybe include an echo statement in the connect file to say "opened file" or something like that. Quote Link to comment Share on other sites More sharing options...
Guest D1proball Posted March 24, 2006 Share Posted March 24, 2006 [!--quoteo(post=357813:date=Mar 23 2006, 07:58 PM:name=JonathanAnon)--][div class=\'quotetop\']QUOTE(JonathanAnon @ Mar 23 2006, 07:58 PM) [snapback]357813[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi, there's a lot of code there. Can I suggest two things first. 1. echo out the SQL statement before the query is run. See that the all the variables are being passed and that the query is being created correctly. You could us phpmyadmin to run this sql statement on the database and make sure that there is not any syntax errors with it. 2. make sure that the connect.php file is okay. also, I use:include('connect.php'); as the code for my includes. I'm not sure if you're way works aswell. It may do but test it out. Maybe include an echo statement in the connect file to say "opened file" or something like that.[/quote]if you press search it works for the first query so i know its connecting, but for some reason it wont list the other results when you click another page. Quote Link to comment Share on other sites More sharing options...
JonathanAnon Posted March 24, 2006 Share Posted March 24, 2006 [!--quoteo(post=357819:date=Mar 24 2006, 01:34 AM:name=D1proball)--][div class=\'quotetop\']QUOTE(D1proball @ Mar 24 2006, 01:34 AM) [snapback]357819[/snapback][/div][div class=\'quotemain\'][!--quotec--]if you press search it works for the first query so i know its connecting, but for some reason it wont list the other results when you click another page.[/quote]are you sure that you are passing the correct variables to the second page. You have to pass them again as either POST or GET varibles. Quote Link to comment 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.