Note that there are some explanatory texts on larger screens.

plurals
  1. POCode to read each row of date in database table
    text
    copied!<p>Currently, I develop a system that will notify user when the warranty of their product will expired soon. If the date is less than 45 days, then an email will send automatically to me. For now, I use below code to send the email. It can run without problem. </p> <pre><code>$days = (strtotime("2013-9-23") - strtotime(date("Y-m-d"))) / (60 * 60 * 24); if ($days&lt;45) include 'sendmail.php'; else { echo "Problem!"; } </code></pre> <p>It might be impossible to code the date one by one. So, I'm thinking that the system can read each row of date in the table itself, but I have no idea to do it. What should I do, so that the code above can read the data without specific it like "2013-9-23" etc. </p> <p>My full code is : </p> <pre><code>// set database server access variables: $host = "localhost"; $user = "root"; $pass = ""; $db = "master_inventory"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = 'SELECT Lap_PC_Name, Lap_War_Expiry FROM laptop'; $date = 'SELECT Lap_War_Expiry FROM laptop'; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) &gt; 0) $days = (strtotime($date) - strtotime(date("Y-m-d"))) / (60 * 60 * 24); if ($days&lt;45) include 'sendmail.php'; else { echo "Problem!"; } while($row = mysql_fetch_array($result)) { $Lap_PC_Name = $row['Lap_PC_Name']; $Lap_War_Expiry = $row['Lap_War_Expiry']; } </code></pre> <p>My sendmail.php code : </p> <pre><code>&lt;?php // set database server access variables: $host = "localhost"; $user = "root"; $pass = ""; $db = "master_inventory"; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM laptop"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) &gt; 10) { for ($query=1; $query&lt;=$result; $query++){ while($row = mysql_fetch_array($result)) { $Lap_PC_Name = $row['Lap_PC_Name']; $Lap_War_Expiry = $row['Lap_War_Expiry']; } } $to = 'nazeni@domain.com'; $subject = 'Testing sendmail'; $message = 'The Following licensed will expired in less than one month. PC Name:'.$Lap_PC_Name. '.The license will expire on '.$Lap_War_Expiry; $headers = 'From: nazeni@domain.com'; if (mail($to, $subject, $message, $headers)) { echo "Email sent."; } else { echo "Email sending failed."; } } ?&gt; </code></pre>
 

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