Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

Search with Multiple fields

Posted 16 Jul 2008 03:48:49
1
has voted
16 Jul 2008 03:48:49 Mike Scott posted:
I have a search form that needs to look for records in a mysql database. what i want is it to look for records using both fields as the criteria and to display. I have it working using one field, but not sure how i go about using both fields. below is the php code that i have at the moment. I'm using dreamweaver for my code.


<pre id=code><font face=courier size=2 id=code>
$colname_rsListing = "-1";
if (isset($_GET['category'])) {
$colname_rsListing = $_GET['category'];
}
mysql_select_db($database_MscottLinx, $MscottLinx);
$query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s", GetSQLValueString($colname_rsListing, "text");
$rsListing = mysql_query($query_rsListing, $MscottLinx) or die(mysql_error());
$row_rsListing = mysql_fetch_assoc($rsListing);
$totalRows_rsListing = mysql_num_rows($rsListing);

</font id=code></pre id=code>

Replies

Replied 16 Jul 2008 19:13:40
16 Jul 2008 19:13:40 Jeff Spijkers replied:
<font face='Arial'>Hi Mike:

I had a similar problem and finally managed to solve it by reviewing the syntax used in MySQL.

Here is the code that I use and it works great! I hope it is what you are looking for.</font id='Arial'>

<pre id=code><font face=courier size=2 id=code>SELECT * FROM table1 WHERE field1=param1 AND field2=param2
(in case you want BOTH conditions to be true)


SELECT * FROM table1 WHERE field1="param1" OR field2="param2"
(when either condition can be true) </font id=code></pre id=code>

Good luck to you.

Saigonjeff
Crap rolls downhill, but that don't mean you gotta wait for it to hit you.

I Use DW8 / PHP / MySQL

Reply to this topic