lucerias Posted November 15, 2006 Share Posted November 15, 2006 I have the following table, how to assign the rate, misc and other value to parameter, $rate, $misc, $other from database table after i do query like if weight < certain kg? Thank you.rate:0.90misc: 1.00other: 2.00weight: X kg Quote Link to comment https://forums.phpfreaks.com/topic/27307-pass-value-from-database-field-to-php-parameter/ Share on other sites More sharing options...
.josh Posted November 15, 2006 Share Posted November 15, 2006 [code]$someweight = 10;$sql = "select * from table where weight < $someweight";$result = mysql_query($sql) or die(mysql_error());while ($list = mysql_fetch_array($result)) { $rate = $list['rate']; $misc = $list['misc']; $other = $list['other'];}[/code]please note that if the query returns more than one result, the variables will be overwritten each time until the last pass of the while loop, resulting in only the last row being grabbed. If you are expecting only 1 row returned, then that's fine. If you are expecting more than one row to be returned, you should meke $rate, $misc, $other arrays like so:[code]$someweight = 10;$sql = "select * from table where weight < $someweight";$result = mysql_query($sql) or die(mysql_error());while ($list = mysql_fetch_array($result)) { $rate[] = $list['rate']; $misc[] = $list['misc']; $other[] = $list['other'];}[/code]or better yet just make one multi-dim array like so:[code]$someweight = 10;$sql = "select * from table where weight < $someweight";$result = mysql_query($sql) or die(mysql_error());while ($list = mysql_fetch_array($result)) { $info[] = $list;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27307-pass-value-from-database-field-to-php-parameter/#findComment-124870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.