Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For 1 row with 2 counter fields use:</p> <pre><code>SELECT SUM(CASE WHEN `check` = 1 THEN 1 ELSE 0 END) AS incomplete, SUM(CASE WHEN `check` = 0 THEN 1 ELSE 0 END) AS complete FROM orders </code></pre> <p>For 2 rows with 1 name use:</p> <pre><code> SELECT COUNT(`ord_number`) AS fulfillment FROM orders WHERE (`check`=0) UNION SELECT COUNT(ord_number) FROM orders WHERE (`check`=1) </code></pre> <p>in which case you need to put row 1 into $complete (check=0) and row 2 into $incomplete (check=1)</p> <p>you may add:</p> <pre><code> UNION SELECT COUNT(ord_number) FROM orders </code></pre> <p>which will give you the total records on row 3.</p> <p>output will be:</p> <pre><code> SELECT * FROM orders ord_number check --------------------- OR123 0 OR124 1 OR125 0 OR126 0 OR127 0 OR123 0 OR125 1 SELECT COUNT(`ord_number`) AS counts FROM orders or1 WHERE (`check`=0) UNION SELECT COUNT(ord_number) FROM orders or2 WHERE (`check`=1) UNION SELECT COUNT(ord_number) FROM orders counts ------- 5 2 7 SELECT SUM(CASE WHEN `check` = 1 THEN 1 ELSE 0 END) AS incomplete, SUM(CASE WHEN `check` = 0 THEN 1 ELSE 0 END) AS complete FROM orders incomplete complete ------------------------- 2 5 </code></pre> <h2>As for PHP:</h2> <p>for 1 row:</p> <pre><code>mysql_select_db($database_test, $test); $query_countIn1Row = " SELECT SUM(CASE WHEN `check` = 1 THEN 1 ELSE 0 END) AS incomplete, SUM(CASE WHEN `check` = 0 THEN 1 ELSE 0 END) AS complete FROM orders"; $countIn1Row = mysql_query($query_countIn1Row, $test) or die(mysql_error()); do { $varIncomplete = $row_countIn1Row['incomplete']; $varComplete = $row_countIn1Row['complete']; } while ($row_countIn1Row = mysql_fetch_assoc($countIn1Row)); </code></pre> <p>and for 1 column with counts:</p> <pre><code>mysql_select_db($database_test, $test); $query_countOrders = "SELECT COUNT(`ord_number`) AS counts FROM orders or1 WHERE (`check`=0) UNION SELECT COUNT(ord_number) FROM orders or2 WHERE (`check`=1) UNION SELECT COUNT(ord_number) FROM orders"; $countOrders = mysql_query($query_countOrders, $test) or die(mysql_error()); $myCounts = array(); do { $myCounts[]= $row_countOrders['counts']; } while ($row_countOrders = mysql_fetch_assoc($countOrders)); $complete = $myCounts[0]; $incomplete = $myCounts[1]; $total = $myCounts[2]; </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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