2014-02-13 24 views
0

我正在編寫一個代碼來從mysql獲取數字數據,然後使用該數據在jpgraphs中生成散點圖。Typecasting來自mysql的數值數據不能在PHP中工作

$f2 = "SELECT `COL 11` FROM `TABLE 1` WHERE 1 LIMIT 1,30;"; 
    $result1 = mysql_query($f2) or die("Cannot verify user " . mysql_error()); 
    if(mysql_num_rows($result1)>0) 
    { 
      $index1=0; 
      while($present_row1= mysql_fetch_assoc($result1)) 
      { 
        $datay[$index1]=(float)$present_row1; 
        $index1++; 
      } 

    } 

    print_r($datay); 

當我將數據類型轉換爲浮點型數據爲十進制值和print_r時,我得到以下輸出。

Array ([0] => 1 [1] => 1 [2] => 1) 

但是,如果不註釋它的數值在那裏,但它們是字符串格式,我不能將它們繪製在圖上。

Array ([0] => Array ([COL 11] => -22039942) [1] => Array ([COL 11] => -26151110)) 

回答

1

$present_row1是一個數組,你不能將它轉換爲浮動。

嘗試:

$datay[$index1]=(float)$present_row1["COL 11"]; 

(這是你$present_row1Array ([COL 11] => -22039942)

+0

謝謝你的工作。 –

+0

不客氣,爲了將來的參考,您可以接受正確的答案(通過檢查左側的灰色標記)。這樣其他用戶會知道正確的解決方案:) – Aquillo

相關問題