2014-01-24 74 views
-3

我希望上述查詢的結果,而不是查詢的結果,查詢本身打印,而不是它的結果?爲什麼?PHP需要

 <?php 

    $host = 'localhost'; 
     $user = 'root'; 
     $passwd = ''; 
    $database = 'p_database'; 
    $connect = mysql_connect($host,$user,$passwd) or die("could not connect to database"); 

    $query = "SELECT DATE(order_time) AS date, SUM(Quantity) AS total_sales 
    FROM ss_orders,ss_ordered_carts 
    GROUP BY date"; 
    mysql_select_db($database); 
    $result = mysql_query ($query,$connect); 

     print "$query"; 
    ?> 
+3

因爲你告訴它'打印 「$查詢」; ' –

+0

我很困惑?我想查詢結果,就像它的總銷售額? ,我不確定這是否是正確的方式,或者我錯過了一些零件 – Shahchaki

+0

您使用什麼教程學習PHP? –

回答

0

您已經打印$查詢,所以請修改代碼

mysql_select_db($database,$connect); 
$result = mysql_fetch_assoc(mysql_query($query)); 
print_r($result); 
+0

我得到資源ID#4?它是什麼? – Shahchaki

+0

更新了代碼,現在嘗試 –

+0

Array([date] => 2014-01-20 [total_sales] => 2)這是我得到的結果?它的權利,但有什麼辦法我只能得到像日期:今天的日期和總銷售:2 – Shahchaki

0

使用Print_recho代替Print

<?php 

    $host = 'localhost'; 
    $user = 'root'; 
    $passwd = ''; 
    $database = 'p_database'; 
    $connect = mysql_connect($host,$user,$passwd) or die("could not connect to database"); 

    $query = "SELECT DATE(order_time) AS date, SUM(Quantity) AS total_sales 
     FROM ss_orders,ss_ordered_carts 
     GROUP BY date"; 
    mysql_select_db($database); 
    $result = mysql_query ($query,$connect); 
    while(mysql_fetch_array($result)){ 
     echo $result[1]; 
    } 

?> 
+0

問題是爲什麼TS獲取查詢而不是結果。用echo和print_r你可以得到mysql結果對象,而不是結果本身。 – Luceos

+0

謝謝先生,但這種方法不會工作 – Shahchaki

+1

@Luceos不會事件'mysql'結果對象。所有這一切都是回聲查詢 - > _「SELECT DATE(order_time)AS日期,SUM(數量)AS total_sales FROM ss_orders,ss_ordered_carts GROUP BY日期」_... – War10ck