Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving specific data from sql query
    primarykey
    data
    text
    <p>Let's say I have the following query, wich gives me the amount of coupons downloaded and redeemed, grouped by date: [EDIT](I can't modify this query)[/EDIT]</p> <pre><code>$sql = "SELECT DATE(datetime) , SUM(CASE WHEN datetime!='' THEN 1 ELSE 0 END) As downloaded , SUM(CASE WHEN used = 1 AND DATE(datetime) != '' THEN 1 ELSE 0 END) AS redeemed FROM Promotion_Redeem WHERE datetime BETWEEN '2013-10-01' AND '2013-10-04' GROUP BY DATE(datetime)"; </code></pre> <p><strong>How can I get the sum of downloaded and the sum of redeemed?</strong> this should be within $sql, somewhere... below is the result for this query:</p> <pre><code>row number 1 array (size=3) 0 =&gt; string '2013-10-01' (length=10) 1 =&gt; string '126' (length=3) 2 =&gt; string '11' (length=2) row number 2 array (size=3) 0 =&gt; string '2013-10-02' (length=10) 1 =&gt; string '106' (length=3) 2 =&gt; string '5' (length=1) row number 3 array (size=3) 0 =&gt; string '2013-10-03' (length=10) 1 =&gt; string '228' (length=3) 2 =&gt; string '12' (length=2) row number 4 array (size=3) 0 =&gt; string '2013-10-04' (length=10) 1 =&gt; string '149' (length=3) 2 =&gt; string '9' (length=1) </code></pre> <p>[EDIT]bove you can see I get 4 rows, each one whith an array... I want, for instance, the sum of the third field from each of these arrays... In my example, this would equals to 37 (that means, 37 coupons redeemed)[/EDIT] I got this data structure after using this:</p> <pre><code>while ($row = mysql_fetch_row($result)) { echo "row number ".++$i; var_dump($row); } </code></pre> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload