PDA

View Full Version : How Do I Show This


Byronwells
03-20-2010, 09:36 AM
Alright Guys

I am trying to work out what is the right mysql/php command to get this to display correctly

I have got a table called smp_categories which has a field in it called id. This records what number position is the category.

I.e if I add category called Master it will record it a position 1, then another category called Private will be recorded with position 2, and so on

I am thinking I can use that id to be able to it under a newest product url link. So that when an user clicks on that link it will show the latest category that we have added to the membership..

My problem is trying to work how to tell mysql/php to do that..

Coyote6
03-24-2010, 05:14 PM
Basically if the id is a primary key and is auto_incremented then your page can just query the database without any variables using the statement.


SELECT MAX(id) FROM smp_categories;


Problem is if someone deletes a record/adds a new one in its place then the new one they created will not be found because it uses a lower id than the max. Using MAX() will find the highest value for id... Which should work 99.99% of the time, with the exception of this case.

DJCMBear
03-25-2010, 06:52 AM
mysql_query("SELECT * FROM table ORDER BY id DESC LIMI 0, 1");