Jump to content

Recommended Posts

Hi,  I am pulling in 3 sets of data from a mysql database and echoing to the screen (the data is to be used to plot a graph); what I need to know is how do I store each set of values in 3 separate arrays for use later in the program. The current code is shown below. Thanks in advance MD :D

 

$query=mysql_query("SELECT * FROM report WHERE report.reportid=$value");

while ($row=mysql_fetch_array($query))

{

  for($x=1; $x<11; $x++)

{

echo $row[$x];

                        }

}

Link to comment
https://forums.phpfreaks.com/topic/238975-php-arrays/
Share on other sites

You can use a multi-dimensional array to keep them altogether, while in separate arrays:

 

$data = array();

while ($row=mysql_fetch_array($query))
{
    $data[] = $row;
}

 

The only small problem with this, is that you're using mysql_fetch_array, which returns the data indexed by both column name and number -- so your array would be twice the size it needs to be. To prevent this you should use either mysql_fetch_row (for numeric array) or mysql_fetch_assoc (for associative array).

Link to comment
https://forums.phpfreaks.com/topic/238975-php-arrays/#findComment-1227987
Share on other sites

Hi

 

Thanks for the replies. The first loop was to select the correct rows within the table and the second loop was to echo the values of each field of the selected rows to the screen. Not sure if this is programmatically correct or not but as a novice it seemed logical!!

 

Will try and solve this over the weekend and report back.

 

Thanks again, MD

Link to comment
https://forums.phpfreaks.com/topic/238975-php-arrays/#findComment-1228003
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.