Jump to content


Photo

why my code print out the last line only ?

php

  • Please log in to reply
1 reply to this topic

#1 rocky7

rocky7

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 18 September 2013 - 08:48 PM

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.";
 }
}
?>


#2 PravinS

PravinS

    Advanced Member

  • Members
  • PipPipPip
  • 428 posts
  • LocationNashik, India

Posted 18 September 2013 - 11:14 PM

if you want to send mails to more than 100 emails ids then your mail code should be in while loop


Thanks & Regards,
PravinS | Blog





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com