Highest Value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Highest Value

Post 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>';
	}
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

SELECT MAX(id) ... 
?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Post Reply