PDA

View Full Version : dynamic select list display details on same page



jonnyfreak
09-16-2012, 05:22 PM
i have a select dropdown list that is showing products from a php msql database. When one of the products is selected from the list in need the details of that product displayed underneath the select list.

here is what i have so far


mysql_select_db($database_beau, $beau);
$query_Recordset1 = "SELECT * FROM beaProdSizes, beauCat WHERE beaProdSizes.CatID = beauCat.catID";
$Recordset1 = mysql_query($query_Recordset1, $beau) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>



<select id="selectName" name="name">
<option value="Select Design">Select Design</option>
<?php
do {
?>
<option value="<?php echo $row_Recordset1['name']; ?>"><?php echo $row_Recordset1['name']; ?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>


thanks in advance

Click SSL
09-17-2012, 09:40 AM
Please use below code for display dynamic option in selection


<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("dbname",$con);

function selectName($postname)
{
$selectqr="select * from tablename order by columnname";
$resqr=mysql_query($selectqr);
if(!$resqr)
{
echo mysql_error();
}
$totqr=mysql_affected_rows();
while($rowqr=mysql_fetch_object($resqr))
{
$name=$rowqr->columnname;

if($postname==$name)
{
$selectobj.="<option value='".$name."' selected>".$name."</option>";
}
else
{
$selectobj.="<option value='".$name."'>".$name."</option>";
}
}
return $selectobj;
}

$displayname="select * from tablename where columnname=condition";
$resdisplayname=mysql_query($displayname);
if(!$resdisplayname)
{
echo mysql_error();
}
$totdisplayname=mysql_affected_rows();
$rowfetch=mysql_fetch_object($resdisplayname);
$name=$rowfetch->columnname;
$displaynamewithsel=selectName($name);
?>
<select name="name">
<option value="">Select Name</option>
<?php echo $displaynamewithsel;?>
</select>

jonnyfreak
09-18-2012, 07:20 PM
i am trying to work out what goes where with the code i already have. i dont want to duplicate code. i have posted the code i already have above. can you show me where your code goes please.

thanks so much for your time