mysql - PHP Drop Down Selected -
i've got 3 drop down boxes populate each drop down 1 above on 3rd drop down want bring value selected. code below
<tr> <td width="119">category</td> <td width="371"> <select name="cat_id" id="cat_id" onchange="showcompany(this.value);"> <option value="">--select--</option> <?php $sql="select * category"; $sql_row=mysql_query($sql); while($sql_res=mysql_fetch_assoc($sql_row)) { ?> <option value="<?php echo $sql_res["id"]; ?>" <?php if($sql_res["id"] ==$_request ["cat_id"]) { echo "selected"; } ?>><?php echo $sql_res["category_name"]; ? ></option> <?php } ?> </select> </td> </tr> <tr> <td>company</td> <td id="td_company"> <select name="company_id" id="company_id">; <option value="">--select--</option> <?php $sql="select * company cat_id='$_request[cat_id]'"; $sql_row=mysql_query($sql); while($sql_res=mysql_fetch_assoc($sql_row)) { ?> <option value="<?php echo $sql_res["id"]; ?>"><?php echo $sql_res["company_name"]; ?></option> <?php } ?> </select> </td> </tr> <tr> <td>item</td> <td id="td_item"> <select name="item_id" id="item_id"> <option value="">--select--</option> <?php $sql="select * item comp_id='$_request[cat_id]'"; $sql_row=mysql_query($sql); while($sql_res=mysql_fetch_assoc($sql_row)) { ?> <option value="<?php echo $sql_res["id"]; ?>"><?php echo $sql_res["item_name"]; ?></option> <?php } ?> </select> </td> </tr> <tr> <td>price</td> <td id="td_item"> <?php $sql="select unit_cost item comp_id='$_request[cat_id]'"; $sql_row=mysql_query($sql); while($sql_res=mysql_fetch_assoc($sql_row)) { echo "<td>" . "£" . $sql_res['unit_cost'] . "</td>"; } ?> </td> </tr> <tr> </tr> </table> </form>
so want bring price option selected, @ moment bringing prices.
e.g. first drop down select cellings company drop down select access panels 3rd drop down 3 items (arm strong, track , screw) , brings 3 prices want able select 1 , bring price. ideas?
first off shouldn't using mysql_* functions, they're deprecated. either mysqli or pdo. second, have vulnerability in code inserting $_request straight sql. that's called sql injection. should reading on it.
with in mind problem query trying select of items company id = category id. query:
$sql="select * item comp_id='$_request[cat_id]'";
notice comp_id='$_request[cat_id]'
should instead comp_id = $_request[comp_id]'
?
Comments
Post a Comment