Page 1 of 1

Highest Value

Posted: Fri Jun 08, 2007 1:54 pm
by psurrena
What I would like to happen is when you click that link it will take the highest ID in the database, add 1 to it and update the database. Now this item is #1. Question is, how do I get the highest ID in my query?

Code: Select all

<?php
	//require '../library/connect.php';
	mysql_connect('localhost','','');
	mysql_select_db(jobs);

	$query = "SELECT id, title, location, date FROM job ORDER BY id DESC";
	$result = mysql_query($query) or die (mysql_error());
	
	if (!mysql_num_rows($result)){
		echo "<p>There are no positions currently available. Please check back soon.</p>";
	} else {
		echo '<table border="0" cellpadding="3" cellspacing="0" width="100%">';
		echo '<tr class="title"><td>Date</td><td>Job Title</td><td>Location</td></tr>';
		while($row=mysql_fetch_assoc($result)) {
			$date = date('m/d/y', strtotime($row['date']));
			
			echo '<tr valign="top"><td class="date">'.$date.'</td><td>';
			echo '<a href="view.php?id='.$row['id'].'">'.$row['title'].'</a><br />';
			echo '<a class="edit" href="#">Move to Top</a> -'; //<--MOVE TO TOP
			echo '<a class="edit" href="edit.php?id='.$row['id'].'">Edit</a> - ';
			echo '<a class="edit" href="delete.php?id='.$row['id'].'">Delete</a>';
			echo '</td><td>'.$row['location'].'</td></tr>';
		}
		echo '</table>';
	}
?>

Posted: Fri Jun 08, 2007 1:58 pm
by John Cartwright

Code: Select all

SELECT MAX(id) ... 
?

Posted: Fri Jun 08, 2007 1:59 pm
by Oren