Jump to content

why my code print out the last line only ?


rocky7

Recommended Posts

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       = '[email protected]';
 $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: [email protected]';
 
 if (mail($to, $subject, $message, $headers)) {
  echo "Email sent.";
 }
 else {
  echo "Email sending failed.";
 }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.