long day silly silly problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

long day silly silly problem

Post by Deddog »

When i enter data for a new date into the booked table the "select" part of the statement allways seems to ignore the first row - why :cry:

if (isset($Submit)){
//$Continue = "NO";
ConnectMeetingRoom();
$Times = "AM";
$idAM = $HTTP_POST_VARS[idAM];
if( strlen($idAM[0])>0 ) {
$IDAM = $idAM[0];
$Break = '-';
$DateArray = array_reverse(explode('/',$TheDate));
$ReturnDate = implode($Break, $DateArray);
$sql="INSERT INTO booked VALUES(NULL,'$IDAM','$ReturnDate','$Times','$EmployeeId')";
mysql_query( $sql );
}
$Times = "PM";
$idPM = $HTTP_POST_VARS[idPM];
if( strlen($idPM[0])>0 ) {
$IDPM = $idPM[0];
$Break = '-';
$DateArray = array_reverse(explode('/',$TheDate));
$ReturnDate = implode($Break, $DateArray);
$sql="INSERT INTO booked VALUES(NULL,'$IDPM','$ReturnDate','$Times','$EmployeeId')";
mysql_query( $sql );
}
mysql_close();
// this is where i send confiramtion emails to the employee who just
//booked a room

ConnectMeetingRoom();
$sql = "select booked.*, rooms.RoomName from booked LEFT JOIN rooms ON booked.RoomsId = rooms.RoomsId
WHERE booked.WhoId = '$EmployeeId' AND booked.BookedDate = '$ReturnDate' ";
$result = mysql_query($sql);
//
if(mysql_num_rows($result)>0):
$row = mysql_fetch_array($result);
$from = "help.desk@csma.uk.com";
$subject = "Meeting Room Confirmation";
$to = $EmployeeEmail;
$Date = date("d M Y");
while ($row = mysql_fetch_array($result)) {
//
//------------------------------------------------------------------------------------
$message = "Senders name: ".$EmployeeName."\n<br>";
$message.= "Date: ".$Date."\n<br>";
$message .= $row["RoomName"]." has been booked on the ". $TheDate ." ".$row["BookedTime"]."\n";
//
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $from";
//
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<font face=Arial size=3 color=\"#ed1c24\"><b>Room booked, confirmation mail sent</b></font><br>";
} else {
echo "<p>Mail could not be sent.</p>";
}
}
//------------------------------------------------------------------------------------
else:
echo "<font face=Arial size=+0 color=\"#CC0000\"><b>There is a Problem obtaining details on the rooms booked</b></font><br>";
endif;
}
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

This is where your problem is:

Code: Select all

if(mysql_num_rows($result)>0): 
    $row = mysql_fetch_array($result); // this is the offending line
    $from = "help.desk@csma.uk.com"; 
    $subject = "Meeting Room Confirmation"; 
    $to = $EmployeeEmail; 
    $Date = date("d M Y"); 
    while ($row = mysql_fetch_array($result)) {
remove the first call to mysql_fetch_array(), which is uneccessary, and then when it's called in the while loop it will start from the first record. So you should have:

Code: Select all

if(mysql_num_rows($result)>0): 
    $from = "help.desk@csma.uk.com"; 
    $subject = "Meeting Room Confirmation"; 
    $to = $EmployeeEmail; 
    $Date = date("d M Y"); 
    while ($row = mysql_fetch_array($result)) {
BTW, it makes code a lot easier to read if you enclose it with [ php ] and [ /php ] (without the spaces).

Mac
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

Thank you sooooooooooo much

Post by Deddog »

:D
Post Reply