There has to be an easier way.. pulling data from mysql
Posted
by
Daniel Hunter
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Hunter
Published on 2011-11-13T01:35:31Z
Indexed on
2011/11/13
1:50 UTC
Read the original article
Hit count: 209
I need to pull 3 values from a table and assign each one to a variable each value is based on to columns, a type and an id
$ht_live_query = mysql_query("SELECT htcode FROM coupon WHERE pid='$pid' AND type='L'");
$ht_live_result = mysql_fetch_array($ht_live_query);
$htCODE_Live = $ht_live_result['htcode'];
You can see that I am assigning the desired value to the variable $htL
$ht_General_query = mysql_query("SELECT htcode FROM coupon WHERE pid='$pid' AND type='G'");
$ht_General_result = mysql_fetch_array($ht_General_query);
$htCODE_General = $ht_General_result['htcode'];
$ht_Reward_query = mysql_query("SELECT htcode FROM coupon WHERE pid='$pid' AND type='R'");
$ht_Reward_result = mysql_fetch_array($ht_Reward_query);
$htCODE_Reward = $ht_Reward_result ['htcode'];
I know I am doing this the hard way but can not figure out how to do the foreach or while loop to attain the desired results.
© Stack Overflow or respective owner