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       = '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.";
 }
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.