Jump to content

combining simple drop down search


stevew

Recommended Posts

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" name="">

 

Pick a color:<br />

<select name="color">

<option value="blue">blue</option>

<option value="green">green</option>

</select>

 

Pick another color<br />

<select name="color2">

<option value="yellow">yellow</option>

<option value="brown">brown</option>

</select>

 

<input type="Submit" name="Submit">

 

<?php

 

$data = mysql_query("SELECT * FROM tbl WHERE color='.$_GET.' AND color2='.$_GET[color2].'")or die(mysql_error());

 

$result  = mysql_fetch_array( $data );

 

This is the part I need some help with. I have 3 fields in the table... id, color, color2. I would like to print or echo all the data matching the search input:

 

(results for drop down input: blue, yellow)

 

id

15 

 

color

blue

 

color2

yellow

______________

 

id 22

 

color

blue

 

color2

yellow

 

etc

 

 

 

 

 

 

 

Link to comment
Share on other sites

Are you having any errors or it's just that you have no idea on how to print results from MySQL? It isn't clear at all.

 

First of all, you'll need to escape input to prevent sql injections. After that, it's as simple as working with arrays.

 

<?php
if ($_GET)
{
$color = mysql_real_escape_string($_GET['color']);
$color2 = mysql_real_escape_string($_GET['color2']);

$results = mysql_query("SELECT * FROM tbl WHERE color='$color' AND color2=$color2");
$values = mysql_fetch_assoc($results);

echo $values['id'].'<br>';
echo $values['color'].'<br>';
echo $values['color2'].'<br>';
}
?>

Link to comment
Share on other sites

Guest
This topic is now 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.