Solved

Getting array from database

Posted on 2013-01-21
2
219 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
Comment Utility
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
Comment Utility
$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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to count occurrences of each item in an array.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now