Copy values to array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rash28
Forum Commoner
Posts: 38
Joined: Wed Aug 01, 2007 1:21 am

Copy values to array

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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>';
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
rash28
Forum Commoner
Posts: 38
Joined: Wed Aug 01, 2007 1:21 am

Post by rash28 »

How to find the max and count in myArray();
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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.
rash28
Forum Commoner
Posts: 38
Joined: Wed Aug 01, 2007 1:21 am

Post 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
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

My post was targeted to rash28 :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post 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:
Post Reply