Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search from multiple fields when only one field was used

Status
Not open for further replies.

phpkata

Programmer
Aug 5, 2004
6
US
I don't know if the title explains my problem very well, but this is what I have:

$query = "SELECT * FROM eny_yarn_identifier WHERE yarnName=\"{$_POST['interest']}\"";

if (isset($yarnColor))
{
$query .= " AND yarnColor=\"{$_POST['interest']}\"";
}
$result = mysql_query($query)
or die ("Couldn't execute query.");
$nrows = mysql_num_rows($result);


It works great if both of the fields are used, but if one is not use, there is no result. Can you tell me what I am doing wrong? Please, if this code makes no sense at all keep in mind I have only been using php and mysql for two days.

Any help would be greatly appreciated!
Thanks,
phpkata
 
you're looking for the same value in both fields?
{$_POST['interest']}

Is this intentional?

P.S. The red is really hard to read on the blue background.



[cheers]
Cheers!
Laura
 
Sorry about the Red ;o)

I meant to type this:

$query = "SELECT * FROM eny_yarn_identifier WHERE yarnName=\"{$_POST['interest']}\"";

if (isset($yarnColor))
{
$query .= " AND yarnColor=\"{$_POST['interest2']}\"";
}
$result = mysql_query($query)
or die ("Couldn't execute query.");
$nrows = mysql_num_rows($result);
 
Hi,
Have you 'echo'ed out your sql statement for both scenarios, to see what it looks like?

Echoing out sql statements is an awesome debugging method, and has saved lots of time for me!


[cheers]
Cheers!
Laura
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top