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

}

 

}

?>

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.