87dave87 Posted October 25, 2006 Share Posted October 25, 2006 Hi, I have a search results page and I want to display $num_rows (so I can put Found 'x' downloads), but my code which has If statements from when it is started is below where I want the $num_rows to appear.e.g. http://www.emulators.cc/ - type 'atari' into the search box at the top and click go... this will display the results but I can't get the 'emulators found' part to work.This is because im not declaring the sql query first, although ive tried to do this...The code for the 'found 'x' emulators is:-[code]<?php$database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$num_rows = mysql_num_rows($sql);echo "<p class='footer'>"; echo $num_rows;echo " emulators found</p>"; ?>[/code]Code for the results to be displayed is: -[code] <?phpif(isset($_POST["emusearch"]) && strlen(trim($_POST["emusearch"])) > 0){ $database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database"); $sql = "select emulator, version, os, platform, details from windows_atari2600 where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc"; if(!$rs = mysql_query($sql)){ echo "Error<br>".mysql_error()."<br>".$sql; exit(); } if(!mysql_num_rows($rs)){ echo "<tr>"; echo "<meta http-equiv='refresh' content='0; URL=http://www.google.com/foundnorecordspage'>"; echo "</tr>\n"; }else{ while ($get_info = mysql_fetch_row($rs)) { echo "<tr>"; foreach ($get_info as $field) echo "<td>$field</td>\n"; echo "</tr>\n"; } } }else{ echo "<meta http-equiv='refresh' content='0; URL=http://www.google.com/searchcriteriarequired'>"; } ?>[/code] Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 You still need a query... Do you want it to show the total in emulators, or just the total found once searched?RegardsHuggie Quote Link to comment Share on other sites More sharing options...
87dave87 Posted October 25, 2006 Author Share Posted October 25, 2006 total found.So if some types in 'stella', at the moment that gives 1, so it will display '1 emulator found' Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 25, 2006 Share Posted October 25, 2006 ok, modified from your code above, give this a try:[code]<?phpif (isset($_POST['emusearch']) && strlen(trim($_POST['emusearch'])) > 0){ $database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database"); $sql = "select emulator, version, os, platform, details from windows_atari2600 where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc"; if(!$rs = mysql_query($sql)){ echo "Error<br>".mysql_error()."<br>".$sql; exit(); } if(!mysql_num_rows($rs)){ echo "<tr>"; echo "<meta http-equiv='refresh' content='0; URL=http://www.google.com/foundnorecordspage'>"; echo "</tr>\n"; } else{ $num_rows = mysql_num_rows($rs); echo "$num_rows results found<br>\n<br>\n"; while ($get_info = mysql_fetch_row($rs)) { echo "<tr>"; foreach ($get_info as $field){ echo "<td>$field</td>\n"; } echo "</tr>\n"; } }}else{ echo "<meta http-equiv='refresh' content='0; URL=http://www.google.com/searchcriteriarequired'>"; } ?>[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
87dave87 Posted October 26, 2006 Author Share Posted October 26, 2006 no... if you do a search now its getting an error for the num_rows?? Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 26, 2006 Share Posted October 26, 2006 Sorry, typo on my part. I corrected it now, can you copy and paste and try again.RegardsHuggie Quote Link to comment Share on other sites More sharing options...
87dave87 Posted October 26, 2006 Author Share Posted October 26, 2006 it works, but as the bar is outside of my result code, I can't do anything with it still. Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 26, 2006 Share Posted October 26, 2006 What bar?Huggie Quote Link to comment Share on other sites More sharing options...
87dave87 Posted October 26, 2006 Author Share Posted October 26, 2006 the yellow 'search results bar' with the php error... thats where im putting the 'found emulators' code. Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted October 26, 2006 Share Posted October 26, 2006 Oh I see what you mean, my bad...Change this:[code]<?php$database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$num_rows = mysql_num_rows($sql);echo "<p class='footer'>"; echo $num_rows;echo " emulators found</p>"; ?>[/code]To this:[code]<?php$database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$sql = "select emulator, version, os, platform, details from windows_atari2600 where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc";$result = mysql_query($sql);$num_rows = mysql_num_rows($result);echo "<p class='footer'>"; echo $num_rows;echo " emulators found</p>"; ?>[/code]RegardsHuggie Quote Link to comment Share on other sites More sharing options...
87dave87 Posted October 26, 2006 Author Share Posted October 26, 2006 k, just done a bit of editting to that and its working fine! thanks a lot... not sure how this has actually worked... but its great! Ill study it later on. 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.