2012-10-09 65 views
0

我需要類似below.的輸出結果。我想爲我的報告生成一個圖形,所以我需要mysql_fetch_assoc中的結果。我對這個概念很陌生。基本上我在做mysql_fetch_array這就是所有,但現在我需要關聯數組函數。php mysql關聯數組用於圖形報告

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

$data = array("28-Sep-2012" => .0032, "27-Sep-2012" => .0028, "29-Sep-2012" => .0021, 
"24-Sep-2012" => .0033); 
+0

這裏我下面的查詢: $結果=請求mysql_query( 「SELECT vaccum_value,日期從vaccum_details其中SERIAL_NUMBER = '10P1005'」); while($ row = mysql_fetch_array($ results)){ \t //我不知道這裏會是什麼? } –

+0

您可以重新生成一個新的數組來實現這一點。 –

回答

0

嘗試這樣,

$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); 
+0

偉大的Prasath先生。它的工作感謝你。你可以解釋嗎? –

+0

@SureshbalajiGunasekaran:這是簡單的PHP數組功能。創建一個數組,其中日期作爲鍵和vaccum_value作爲數組值。 –

+0

但我需要像這樣的數組(「28-Sep-2012」=> .0032,「2012年9月27日」=> .0028,「2012年9月29日」=> .0021, 「 Sep-2012「=> .0033);而不是[]方括號我需要「」老闆...在我運行腳本與我的代碼CodeGo.net,我得到了這樣的輸出數組([2012年9月28日] => 31.6 [2012年10月4日] => 0.99 [03-Oct-2012] => -3); –