Hi, i need some help with my dropdown list which is populated by a mysql db. I also have a fully working search text box. What i want to be able to do is when something is selected from the dropdown list i want it to search like the text box and only bring up that data.
query for dropdown list
Dropdownquery.php
[php]<?php
include_once 'db.con.php';
function connect(){
mysql_connect(DB_HOST,DB_USER,DB_PASS) or die ('Could not connect to database ' .mysql_error());
mysql_select_db(DB_NAME);
}
function close(){
mysql_close();
}
function query(){
$myData = mysql_query("SELECT * FROM publisher");
while($record = mysql_fetch_array($myData)){
echo'<option value="' . $record['publisher'] . '">' . $record['publisher'] . '</option>';
}
}
?>[/php]
search query
search.php
[php]<?php
include_once ‘dropdownquery.php’;
connect();
include_once 'db.con.php';
connect();
?>[/php]
[php] <?php
$k = $_GET[‘k’];
$terms = explode(" ", $k);
$query = "SELECT * FROM search WHERE ";
foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "keywords LIKE '%$each%' ";
else
$query .= "OR keywords LIKE '%$each%' ";
}
// connect
mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db("search");
$query = mysql_query($query);
$numrows = mysql_num_rows($query);
if ($numrows > 0){
while ($row = mysql_fetch_assoc($query)){
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['keywords'];
$link = $row['link'];
echo "<br /><h3><a href='$link'>$title</a></h3>
$description";
}
}
else
echo "No results found for \"<b>$k</b>\"";
//disconnect
mysql_close();
?>[/php]
Form Code
[code]
<select name="dropdown" style="font-family: 'ariel'; font-size: 17px; width: 190px; height: 27px; position:absolute; left: 385px; top: 251px">
<?php query() ?>
</select>
<?php close() ?>
<input type="text" name="k" size="50" onfocus="if (this.name=='k') this.name=''; value="<?php echo $_GET["k"]; ?>" style="width: 203px; position:absolute; left: 586px; top: 251px; height: 27px; right: 567px; border:thin red solid" />
<input id="button" type="submit" value="Search" style="position:absolute; left: 800px; top: 251px; height: 27px;" />
<input type="reset" id="button" style="position:absolute; left: 873px; top: 251px; height: 27px; width: 57px; value="Reset"/>
[/code]
Ive been trying to get this to work for ages if anyone can help that would be great thanks.