stig1 Posted September 11, 2008 Share Posted September 11, 2008 How do you put a different value into each variable out of a database. The data will be all in the same column, but on different rows. Here is my code. $sql = "SELECT mName, mFigure FROM tbl_margins WHERE mSelect = 1; $mResult = mysql_query($sql) or die (mysql_error()); while ($margin = mysql_fetch_array($mResult)){ $marginA = $margin["mFigure"]; $marginB = $margin["mFigure"]; $marginC = $margin["mFigure"]; } I would have 3 margins pulled out of the database now in that statement. How do I put each one of those values into a different variable to use later. Would be better if I could put each of the values into global so I can access them when needed. Thankyou for all your help in advanced. Link to comment https://forums.phpfreaks.com/topic/123843-help-with-data-from-mysql-table/ Share on other sites More sharing options...
gbunny Posted September 12, 2008 Share Posted September 12, 2008 I'm not really sure I understand what you're asking, but here's a shot. When I do this I always set a count and use an array. $sql = "SELECT mName, mFigure FROM tbl_margins WHERE mSelect = 1; $mResult = mysql_query($sql) or die (mysql_error()); $count = 0; //count to increase array index while ($margin = mysql_fetch_array($mResult)){ $m[$count] = $margin['mFigure']; //set value in array to value from database $count++; //increase count } Link to comment https://forums.phpfreaks.com/topic/123843-help-with-data-from-mysql-table/#findComment-639489 Share on other sites More sharing options...
stig1 Posted September 12, 2008 Author Share Posted September 12, 2008 Then how would i be able to use those three different values in different formula's. Basically I have a site with 3 price breaks, thats why different margins. However in the database, there is a table of records and the boss selects three margins. Basically I just need to be able to have three different values in a variable name out of that database table. If I can set these values to a global variable, that would be even better. Link to comment https://forums.phpfreaks.com/topic/123843-help-with-data-from-mysql-table/#findComment-639547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.