|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading the last five entries in database from bottom to top
I have a database called main_news with three fields: Subject, Text and an auto-incrementing field called newsid.
I want to read out the last five news posts from bottom to top, so if i post something it comes out first and the other 4 below it. I want the subject to come out first and in bold, then a <br> and then the text of the news, then a <br> then the next subject etc. I have been stuck on figuring out how exactly to do this.. any help is appreciated, thanks in advance. |
|
#2
|
||||
|
||||
|
RE: Reading the last five entries in database from bottom to top
|
|
#3
|
|||
|
|||
|
RE: Reading the last five entries in database from bottom to top
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ecliptic/public_html/index.php on line 34
i get that when i use your code while($result=mysql_fetch_array($do)) { print "<b>".$row["subject"]."</b><br>"; print $row["text"]."<br>"; } |
|
#4
|
||||
|
||||
|
RE: Reading the last five entries in database from bottom to top
|
|
#5
|
|||
|
|||
|
RE: Reading the last five entries in database from bottom to top
I changed the $do to $result and im still getting the same error
|
|
#6
|
|||
|
|||
|
RE: Reading the last five entries in database from bottom to top
I noticed another error in the code, try this...
<?php $conn=mysql_connect("localhost","",""); mysql_select_db("",$conn); $result=mysql_query("select * from main_news order by newsid desc limit 0,5"); while($row=mysql_fetch_array($result)) { print "<b>".$row["subject"]."</b><br>"; print $row["text"]."<br>"; } mysql_close($conn); ?> Changed the variable $result to $row in the while statement. Seems to work for me |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Reading the last five entries in database from bottom to top |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|