Solved

Getting array from database

Posted on 2013-01-21
2
226 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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