Jump to content

Newbie... cant get if stmnt to echo if query returned no results


megazign

Recommended Posts

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++ ;

}

 

}

?>

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;

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.