Solved

Getting array from database

Posted on 2013-01-21
2
223 Views
Last Modified: 2013-01-21
Hi all,

I'm still learning PHP and am having some trouble creating an array that I can add the info to a PHP Chart.

Here is my call to the database.  

$query = mysql_query("SELECT * FROM exercising_table WHERE uname = '$username' ");

Open in new window


Field names:

uname
exercise_id (primary key)
exercise_duration (int in minutes)
exercise_timestamp

and I need to output the array in this format:

 
          ['24/01/12',  25],
          ['25/01/12',  26],
          ['28/01/12',  27],
          ['24/02/12',  25],
          ['15/03/12',  26],
          ['24/04/12',  27],
          ['21/06/12',  11]
        

Open in new window


The first column is the date (to be taken from exercise_timestamp) and the second column is the exercise time (to be taken from exercise_duration)

Could anyone assist me with this?

Thank you so much.
0
Comment
Question by:TLN_CANADA
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 38803892
try:
$username=mysql_real_escape_string($username);
$result=array();
$query = mysql_query("SELECT exercise_timestamp,exercise_duration FROM exercising_table WHERE uname = '$username' ");
while( $result[]=mysql_fetch_assoc($query)){}
print_r($result);

Open in new window

0
 
LVL 2

Expert Comment

by:rossdalangin
ID: 38803922
$query = mysql_query("SELECT exercise_timestamp,exercise_duration FROM exercising_table WHERE uname = '$username' ");

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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question