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 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] 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
Archived
This topic is now archived and is closed to further replies.