HTML/Javascript

SES by business degree online promotion team.

Philippine Airlines International Flight schedules

Philippine Airlines International Flight schedules
Philippine Airlines International Flight schedules

Search This Blog

Wednesday, October 27, 2010

Max Function & sql display the highest number field data from mysql database

Display the highest number data from MySql Database

<?php
//protected area orig3 file
$query = "SELECT MAX(ttravelid) FROM travelid";
$resultx = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($resultx))
{
//echo "The most highest reservation id is ".$row['MAX(reservationid)'];
$ttravelid1 = $row['MAX(ttravelid)'];
//echo $ttraveliddd;
}
//this is the max number
echo $ttravelid1;

?>

or you can use sql, this will display the highest id number of the personal data.

<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM person order by id DESC limit 1");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

No comments:

Post a Comment