rocky7 Posted September 19, 2013 Share Posted September 19, 2013 This is my coding. It can run, but the only thing is, it will print out the last line of the data in the table. Why is that happening ? Because I have more than 100 data. <?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) > 0) { while($row = mysql_fetch_array($result)) { $Lap_PC_Name = $row['Lap_PC_Name']; $Lap_War_Expiry = $row['Lap_War_Expiry']; } $to = 'abc@xyz.com'; $subject = 'Testing sendmail'; $message = 'The licensed for the following PC will expired in less than one month. PC Name : '.$Lap_PC_Name. '.Date of expired is : ' .$Lap_War_Expiry; $headers = 'From: abc@xyz.com'; if (mail($to, $subject, $message, $headers)) { echo "Email sent."; } else { echo "Email sending failed."; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/282268-why-my-code-print-out-the-last-line-only/ Share on other sites More sharing options...
PravinS Posted September 19, 2013 Share Posted September 19, 2013 if you want to send mails to more than 100 emails ids then your mail code should be in while loop Quote Link to comment https://forums.phpfreaks.com/topic/282268-why-my-code-print-out-the-last-line-only/#findComment-1450191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.