How to relate two column in PHP MYSQL -
i have created 1 request table contain request information.
the table containing these columns:
requestid , itemrequest1, itemrequest2, itemrequest3, quantity1, quantity2, quantity3
how make relation if itemrequest has value in column itemrequest2, take quantity column quantity2.
my query this:
$query2=mysql_query("select * tbl_request unit='$unit' , (itemrequest1='$itemrequest' or itemrequest2='$itemrequest' or itemrequest3='$itemrequest')"); $record_num=mysql_num_rows($query2); while ($data1 = mysql_fetch_array($query2)) the problem when $itemrequest has value in column itemrequest3, quantity show quantity column 1.
you can use conditions in query in order select right column depending on column's value.
select requestid, (case when itemrequest1 = '$itemrequest' quantity1 else ( case when itemrequest2 = '$itemrequest' quantity2 else ( case when itemrequest3 = '$itemrequest' quantity3 end) end) end) tbl_request you should have close database structure though, if have things this, might better improve structure , have better tables/fields.
Comments
Post a Comment