Jump to content

Simple Problem! Not complex, well I don't think so!


stig1

Recommended Posts

Having a blank at the moment people.

 

Wondering if someone could help me out here.

 

Currently I have the following table built in mysql

 

id

name

percent

select

1

priceA

305

1

2

priceB

263

0

3

priceC

225

1

4

priceD

208.8

0

5

priceE

176.2

1

 

I run a query to only select the rows that have got select = 1

 

How do I put each row data into a different varaible name or extract the data out of the array I get from mysql_fetch_array function.

 

I need to use each different percent value return outside of the while loop statement, that has 1 selected to build prices on the website.

 

for example:

 

$marginsSQL = "SELECT * FROM tbl_margins WHERE select = 1";
$marginsResult = mysql_query($marginsSQL) or die (mysql_error());
while ($margins = mysql_fetch_array($marginsResult)){ 
$percent = $products["percent"];
}

 

Any solutions? Having a very big blank at the moment.

 

Thanks guys :)

Link to comment
Share on other sites

I already changed that line! I made a typo.

 

If I run echo inside the while they all print out correctly.

 

However outside the while statement, I would like to be able to put each of the return records into a variable of there own.

 

Eg

 

MarginOne = $percent; // First returned value in the sql statement

MarginTwo = $percent; // Second returned value in the sql statement

MarginThree = $percent; // Third returned value in the sql statement

 

All of them return the same value. I require them to be different!

Link to comment
Share on other sites

Make $percent an array.

 

$marginsSQL = "SELECT * FROM tbl_margins WHERE select = 1";
$marginsResult = mysql_query($marginsSQL) or die (mysql_error());
$percent = array();
while ($margins = mysql_fetch_array($marginsResult)){ 
$percent[] = $products["percent"];
}
print_r($percent);

Link to comment
Share on other sites

I have created the following function.

 

// Default Margins

function margins() {

	$margins = array();

	$mSQL = "SELECT mMargin FROM tbl_margins WHERE mSelect = 1";

	$mResult = mysql_query($mSQL) or die(mysql_error());

	while ($m = mysql_fetch_array($mResult)) {

		$margins[] = $m["mMargin"];

	}	

	// print_r($margins);

	$mSingle = $margins[0];

	$mBulk = $margins[1];

	$mPallet = $margins[2];

}

 

The function returns the correct values.

 

However when i call the function margins(); and then try to echo out $mSingle, $mBulk, $mPallet there is no value defined.

 

Any solutions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.