1

In the program, I want to create table to print out the date in (Y/M/D) format, volume, pending and sent. However, it show nothing after execution. It can be executed using phpmyadmin in the SQL. However, I do not know whether we can use two SQL statements to find out two different condition. I need your help.

$start = date('2013-12-12');
$today = date("Y/m/d");
echo "Today's date: " .$today;
$result = mysql_query("SELECT count(semail) AS av FROM table WHERE `thedate`>='2013-12-12' GROUP BY `thedate` ")or die(mysql_error());  
$row = mysql_fetch_assoc($result) or die("No rows returned by query"); 
$totalofemail = $row['av'];
$sent = mysql_query("SELECT count(semail) AS av FROM table WHERE `sflag`='1' AND `thedate`>='2013-12-12' GROUP BY `thedate`")or die(mysql_error());  
$result = mysql_fetch_assoc($sent) or die("No rows returned by query");  
$sentemail = $result['av'];
$pending = $totalofemail - $sentemail;

echo "<table border='1'>
      <tr>
        <th>Date</th>
        <th>Daily volume</th>
        <th>Sent</th>
        <th>Pending</th>
      </tr>";

if($i=0; $i<($today-$start); $i++)
{
   echo "<tr>\n";
   echo "<td>" . $row['thedate'] . "</td>\n";
   echo "<td>" . $totalofemail . "</td>\n";
   echo "<td>" . $sentemail . "</td>\n";
   echo "<td>" . $pending . "</td>\n";
   echo "\n</tr>\n";
   echo "</table>\n";
}

2 Answers 2

3

Reason for the error is if($i=0; $i< ($today-$start); $i++)

But in your code, there is no need of using for loop

try using,

for($i=0; $i< ($today-$start); $i++)

instead of

if($i=0; $i< ($today-$start); $i++)

Code: Removed loop condition. since there is no neccessity for the loop.

$start = date('2013-12-12');
$today = date("Y/m/d");
echo "Today's date: " .$today;
$result = mysql_query("SELECT count(semail) AS av FROM mycard WHERE `thedate`>='2013-12-12' GROUP BY `thedate` ")or die(mysql_error());  
$row = mysql_fetch_assoc($result) or die("No rows returned by query"); 
$totalofemail = $row['av'];


$sent = mysql_query("SELECT count(semail) AS av FROM mycard WHERE `sflag`='1' AND `thedate`>='2013-12-12' GROUP BY `thedate`")or die(mysql_error());  
$result = mysql_fetch_assoc($sent) or die("No rows returned by query");  
$sentemail = $result['av'];


$pending = $totalofemail - $sentemail;

echo "<table border='1'>
      <tr>
        <th>Date</th>
        <th>Daily volume</th>
        <th>Sent</th>
        <th>Pending</th>
      </tr>";

      echo "<tr>\n";
      echo "<td>" . $row['thedate'] . "</td>\n";
      echo "<td>" . $totalofemail . "</td>\n";
      echo "<td>" . $sentemail . "</td>\n";
      echo "<td>" . $pending . "</td>\n";
      echo "\n</tr>\n";


   echo "</table>\n";
Sign up to request clarification or add additional context in comments.

5 Comments

Sorry, is 'for'loop not 'if'. Yet,after executing the table would not shown that a statement 'No rows returned by query' is shown
FROM yourtablename what is your table name? replace yourtablename
yourtablename = mycard
Then replace table by mycard in your sql query, I have updated my answer aswell.
@user876345. Is it not better to make a complete string. (by concatenation) and echo to the browser only once
1

What did you want to do? A new perspective?

    if($i=0; $i<($today-$start); $i++)

Should not it be for?

for($i=0; $i<($today-$start); $i++)

Another "boring" part is about using mysql_* functions. As we all know they are deprecated. Use mysqli_* or PDO instead.

1 Comment

Sorry, it is 'for'loop not 'if'. Yet,after executing the table would not shown that a statement 'No rows returned by query' is shown

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.