0

i need the output like below.i want to generate a graph for my report so i need the result in mysql_fetch_assoc. i am new to this concept. basically am doing mysql_fetch_array thats all but now i need the associative array function.

$date = array("date" => reading);

$data = array("28-Sep-2012" => .0032, "27-Sep-2012" => .0028, "29-Sep-2012" => .0021,
"24-Sep-2012" => .0033);
2
  • here below my query: $results = mysql_query("SELECT vaccum_value,date FROM vaccum_details where serial_number='10P1005'"); while($row = mysql_fetch_array($results)) { // i don't know what would be here? } Commented Oct 9, 2012 at 11:19
  • You can regenerate a new array to achieve this. Commented Oct 9, 2012 at 11:26

1 Answer 1

0

Try like this,

$results = mysql_query("SELECT vaccum_value,date FROM vaccum_details where serial_number='10P1005'");
$data=array();
while ($row = mysql_fetch_array($results))
{ 
    $data[$row['date']]=$row['vaccum_value'];
}

print_r($data);
Sign up to request clarification or add additional context in comments.

3 Comments

@SureshbalajiGunasekaran: This is the simple PHP array functionality. create an array with date as key and vaccum_value as a array value.
but i need the output like this array("28-Sep-2012" => .0032, "27-Sep-2012" => .0028, "29-Sep-2012" => .0021, "24-Sep-2012" => .0033); instead of [] square bracket i need "" boss... after i run the script with ur code i got a output like this Array ( [28-Sep-2012] => 31.6 [04-Oct-2012] => 0.99 [03-Oct-2012] => -3 );
both are same.. the key of the array is string only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.