Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access array's values by its key

Tags:

arrays

php

I have this code which shows the total sale up till the current date , but it shows in this way

Array ( 
       [Date] => 2014-01-25 
       [TotalSales] => 7
      )

Is there any way , where i can show in this way Total Sale:7 And Date:2014-01-25 ?

<?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 TotalSales
    FROM ss_orders,ss_ordered_carts
    WHERE DATE(order_time) = DATE(NOW())
    group by date;";

    mysql_select_db($database,$connect);
    $result = mysql_fetch_assoc(mysql_query($query));
    print_r($result);
?>
like image 760
user3234335 Avatar asked Mar 21 '23 19:03

user3234335


1 Answers

You are using print_r which Prints human-readable information about a variable . You can access the value by name

echo "TotalSale: ".$result['TotalSales'];
echo "Date: ".$result['Date'];
like image 181
Linga Avatar answered Apr 10 '23 08:04

Linga