Solved

Getting array from database

Posted on 2013-01-21
2
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

615 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