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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to display data from db after choosing value from drop down 1

Status
Not open for further replies.

amir4oracle

Programmer
Nov 3, 2004
46
0
0
CA
hello,

i need to know how can i display data from database using drop down.

in other words, i have to create a drop down using select-option and depending upon the choosen value i need to display the values in the row using select query.

Your help is highly appreciated.


 
What have you done so far? Where are you stuck? We can help with individual problems, but all we can tell you is this:

1. create a dropdown and a button
2. submit
3. on the next page, construct your query in a way to include the sent element.
4. run query.
 
I did exactly as you said Vragabond ... and its working perfectly
gave you the star :)
thanks a lot
 
Lookie, lookie:
Code:
<?php
if (empty($cat)) {
$cat = "fafafafa";
}

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category ORDER BY category ASC");
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($cat) and strlen($cat) > 0){
//her
$query = sprintf("SELECT DISTINCT subcategory FROM subcategory where cat_id=%s order by subcategory",
           quote_smart($cat));
$quer = mysql_query($query);
}else{$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory ORDER BY subcategory ASC"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
//reload(this.form)
echo "<form method=\"post\" name=\"f1\" action=\"index.php\"  enctype=\"multipart/form-data\">";

/// Add your form processing page address to action in above line. Example  action=dd-check.php////
//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"document.f1.submit()\"><option value=\"falaffel\">Velg en dyreart</option>";
while($res2 = mysql_fetch_array($quer2)) {

if($res2['cat_id']==@$cat){
echo "<option selected value='$res2[cat_id]'>$res2[category]</option>";}
else{echo  "<option value='$res2[cat_id]'>$res2[category]</option>";}
}
echo "</select>";

echo "<input type=\"text\" name=\"__annen_kategori\" value=\"{$_POST['__annen_kategori']}\" style=\"width:106px; padding-left: 10px;\" /><br />";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat' style=\"width:336px;\">";
while($res = mysql_fetch_array($quer)) {
$subcat = str_replace("!", "", $res[subcategory]);
echo  "<option value='$subcat'>{$subcat}</option>";
}
echo "</select>";
?>

I made this based on some js-code I found while googling.
It will submit to self, when choosing from list.

Olav Alexander Mjelde
Admin & Webmaster
 
oh, you need this too:
Code:
// Quote variable to make safe
function quote_smart($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }
   // Quote if not a number or a numeric string
   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value) . "'";
   }
   return $value;
}

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top