megazign Posted October 14, 2010 Share Posted October 14, 2010 here is my code... please help <form method="get" action="shit3.php"> <input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="SEARCH"> </form> <?php if (@$_GET['q']) { $var = $_GET['q'] ; $trimmed = trim($var); $limit=1; if ($trimmed == "") { echo "Please enter a search..."; exit; } if (!isset($var)) { echo "Container not found!"; exit; } mysql_connect("localhost", "xxx", "yyy") or die(mysql_error()); mysql_query("SET NAMES 'cp1251'"); mysql_select_db("agaexpor_container") or die("Unable to select database"); //select which database we're using $query = "select * from containertracking where vin like \"%$trimmed%\" order by vin"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); $count = 1 + $s ; while ($row= mysql_fetch_array($result)) { $vin = $row["vin"]; $container = $row["container"]; echo "$count.) VIN: $vin <br />"; echo "container is: $container <br />"; $count++ ; } } ?> Link to comment https://forums.phpfreaks.com/topic/215833-newbie-cant-get-if-stmnt-to-echo-if-query-returned-no-results/ Share on other sites More sharing options...
trq Posted October 14, 2010 Share Posted October 14, 2010 You don't have any if statement that check if your query returned any results or not. Link to comment https://forums.phpfreaks.com/topic/215833-newbie-cant-get-if-stmnt-to-echo-if-query-returned-no-results/#findComment-1122017 Share on other sites More sharing options...
megazign Posted October 14, 2010 Author Share Posted October 14, 2010 ohh... I am modifying a script that I found with a script that I wrote based on a tutorial. The search works, but I need to include an if statement that say: If no container is found, echo no matching containers. elseif the field value = 0, then echo please enter a vin number... I thought this was supposed to do the trick: if (@$_GET['q']) { $var = $_GET['q'] ; $trimmed = trim($var); $limit=1; if ($trimmed == "") { echo "Please enter a search..."; exit; } if (!isset($var)) { echo "Container not found!"; exit; } Link to comment https://forums.phpfreaks.com/topic/215833-newbie-cant-get-if-stmnt-to-echo-if-query-returned-no-results/#findComment-1122020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.