Forum Moderators: coopster

Message Too Old, No Replies

Manipulating a mysql query result

Missing something here

         

GGR_Web

8:27 am on Aug 4, 2009 (gmt 0)

10+ Year Member



Hi.

I need to pull data from a mysql table and feed it into a prebuilt function, which accepts arrays as input.

I can use mysql_query successfully and display results with while fetch array - but I can't seem to find any infomation on how to take the array ($result for example) and use it in another array. Here's what I have:

$arr = Array(
'First Trimester' => Array(1000,200,100,1000,50),
'Second Trimester' => Array(1200,200,200,10,20),
'Third Trimester' => Array(-500,23,255,100,15)
);

The important vaule being the first.

I imagine it would look like this:
first trimester => array ($valuepulledfromresult, 200, 100, 50)

I'm just now entirely sure how to achieve this.

andrewsmd

8:35 pm on Aug 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not really for sure what you are asking. If you want to set it to a 2d array then you just have it exactly like you posted. Can you explain a little more and possibly give and example?

messageboy

11:37 pm on Aug 4, 2009 (gmt 0)

10+ Year Member



You could make a preset empty array which then use array merge to merge the sql array with the empty array.

[au2.php.net...]

GGR_Web

2:03 pm on Aug 5, 2009 (gmt 0)

10+ Year Member



Thanks for your replies

I've had some thought about this - I think I've got it.

I can do this (answering my own question)
$example = $row{'title'];

And I think I can use a while loop to extract as many new variables as possible. Something like $example[1], $example[2] ect.

The question is how do I set a while loop to add 1 to the variable number every time?

andrewsmd

2:17 pm on Aug 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



//initialize a counter
$count = 1;

//this is just showing you how to
//use a counter your while could
//contain any condition. in your
//specific reference it would be
//the wile loop that goes through all of
//your data
while($count <= 10){
//here is the example to show
//the counter
echo("the counter for example is" $count);
$count++;
}

Run that code really quick it should explain it to you.