Printing result of mysql query from variable

后端 未结 4 1973
日久生厌
日久生厌 2021-02-07 15:58

So I wrote this earlier (in php), but everytime I try echo $test\", I just get back resource id 5. Does anyone know how to actually print out the mysql query from the variable?<

4条回答
  •  感情败类
    2021-02-07 16:35

    This will print out the query:

    $query = "SELECT order_date, no_of_items, shipping_charge, SUM(total_order_amount) as test FROM `orders` WHERE DATE(`order_date`) = DATE(NOW()) GROUP BY DATE(`order_date`)";
    
    $dave= mysql_query($query) or die(mysql_error());
    print $query;
    

    This will print out the results:

    $query = "SELECT order_date, no_of_items, shipping_charge, SUM(total_order_amount) as test FROM `orders` WHERE DATE(`order_date`) = DATE(NOW()) GROUP BY DATE(`order_date`)";
    
    $dave= mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_assoc($dave)){
        foreach($row as $cname => $cvalue){
            print "$cname: $cvalue\t";
        }
        print "\r\n";
    }
    

提交回复
热议问题