Jump to content

Help with Data from Mysql Table.


stig1

Recommended Posts

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

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
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.