Click here to Skip to main content
16,022,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys i am having problem in selecting the maximum of number of a column called booking id, in a 'booking' table

i wrote my sytax like this
PHP
<?php

include 'configuration.php';

$sql= mysql_query("select max(booking_id) from booking ");

if(!$sql){echo "syntax error";}else{

while($row = mysql_fetch_array($sql)){

        $booking_id = $row['booking_id'];

        echo $booking_id;
    }
}



?>


but it is giving me an error like this ...
( ! ) Notice: Undefined index: booking_id in C:\wamp\www\airlines\test.php on line 11
Call Stack
# Time Memory Function Location
1 0.0009 324472 {main}( ) ..\test.php:0
Posted
Comments
Mohibur Rashid 7-Mar-15 10:06am    
You are getting this error because your index is "max(booking_id)". Two ways of getting out of this error,
1. using max(booking_id) as index or assigning an alternative name for your column. ie "select max(booking_id) as booking_id from booking "
2. as Peter leow said

1 solution

There is no need for while loop as you are expecting one result only for the max booking_id, And you are expecting array, use index to get the result will do.
$row = mysql_fetch_array($result);
$booking_id = $row[0];
echo $booking_id;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900