|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do you find the highest id number
I am making a news script where it can only show 1 news item at a time and the latest one needs to always to be seen
I am using id with auto increment and therefore the newsest post will be the highest id number i wonder if u could help me by showing me how to automatically show the latest news item this is what i have so far <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM webnews WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <? $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $by=mysql_result($result,$i,"by"); $snews=mysql_result($result,$i,"snews"); $fnews=mysql_result($result,$i,"fnews"); $date=mysql_result($result,$i,"date"); ?> <p><? echo "$id"; ?></p> <p><? echo "$by"; ?></p> <p><? echo "$snews"; ?></p> <p><? echo "$fnews"; ?></p> <p><? echo "$date"; ?></p> <? ++$i; } ?> -------------------------------------------- I may be going to wrong ray around it so any help would do thank you |
|
#2
|
||||
|
||||
|
To get just the most recent news item, build your query as follows:
Code:
SELECT * FROM webnews ORDER BY id DESC LIMIT 1 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > How do you find the highest id number |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|