Page 1 of 1

Copy values to array

Posted: Fri Sep 21, 2007 2:40 am
by rash28
I have a problem regarding copying the results from mysql_fetch_assoc

Code: Select all

while($row = mysql_fetch_assoc($result)) {
echo $row['fielsname'];

How to copy the values to array.

Posted: Fri Sep 21, 2007 2:58 am
by s.dot
they're already in an array. $row is an array.

Code: Select all

print_r($row);
However, if you want to store them in an additional array..

Code: Select all

$myArray = array();

while($row = mysql_fetch_assoc($result))
{
    $myArray[] = $row['fielsname'];
}

//echo '<pre>';
//print_r($myArray);
//echo '</pre>';

Posted: Fri Sep 21, 2007 3:35 am
by rash28
How to find the max and count in myArray();

Posted: Fri Sep 21, 2007 7:38 am
by xpgeek
rash28 wrote:How to find the max and count in myArray();
To find max you need to walk through array and copy maximum value into variable.

To count you can use sizeof and count functions.

Posted: Fri Sep 21, 2007 7:53 am
by rash28
Hi,

Code: Select all

$max=max($graphValues);
But the maximum value is not fetched.

Code: Select all

$count=count($graphValues);
The output is not just the count of all.
It is 1,2,3............................ last record.


Please help me with this

Posted: Fri Sep 21, 2007 8:03 am
by Stryks
Sandy1028 ???

Just out of interest ... why do you keep changing variable names between replies? If it's not working as $myArray, it's not likely to start working as $graphValues.

What was your output from print_r($whatever_you_call_it)?

What results did you get from max and count?

Posted: Fri Sep 21, 2007 8:53 am
by VladSun
I can't understand something - why one would want to do "max" and "count" at code layer, when he could do this at DB layer?

Posted: Fri Sep 21, 2007 9:07 am
by Stryks
Well ... I'm just putting two and two together here, and if I'm wrong I apologize, but I think that line of thought has already been attempted without success.

We want to help you, seriously, but it's really hard to guess your problems, especially if you don't give us an idea of the data you're handling and what you're trying to accomplish.

No-ones really interested in your code or data if thats what you're worried about. No-one's going to run off with it.

If something doesn't work, post the problem code and a sample of the output. It's important to also show the code that gives the output.

Just trying to help out.

Posted: Fri Sep 21, 2007 9:16 am
by VladSun
My post was targeted to rash28 :)

Posted: Fri Sep 21, 2007 9:31 am
by Stryks
Yeah ... I was just having a gentle rib at the double posting.

Seemed nicer to frame it as a response to you. And now you've gone and ruined it all ... :lol: