|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||||
|
|||||
|
problem retreving information from mySQL database
Hi, my name's Herb and I've been coding in php for about two months now.
I've been working on a news script that uses mysql to store the actual news and user informaion. But I'm having a problem with displaying the actual news from the database as i want it to be displayed. I was using the following code to do so: php Code:
The code displays the first 5 enteries made to the database. I wanted it to display the 5 most recent entries, starting with the most recent entry. Now i've tried using mysql_num_rows($resultID) as the variable $i and then using another variable to equal 5 less than that using an expression similar to: but i would either end up with the same results. So, does anyone have any ideas on how i could get this script to display the 5 most recent posts? |
|
#2
|
|||
|
|||
|
RE: problem retreving information from mySQL database
outside of MySQL (since i have yet to learn it) you could give each news entry an ID timestamp of the date it was created, then read through each ID while storing them into an array and then sort the array from lowest to highest (the highest being the most recent update) and then reverse the array to display the top 5 :-D
|
|
#3
|
|||
|
|||
|
RE: problem retreving information from mySQL database
use this for your query :
SELECT date, subject, news, status, email, username FROM updates ORDER BY date DESC LIMIT 5 |
|
#4
|
|||
|
|||
|
RE: RE: problem retreving information from mySQL database
Quote:
thank you Anonymous user! With a little bit of tweaking, my script worked perfectly! can you beleve i've spent all day trying to fix that one problem? LOL |
|
#5
|
|||
|
|||
|
RE: problem retreving information from mySQL database
In the tutorial "Create dynamic sites with PHP & MySQL", how does one reverse the order of listing. The way there are listed now are be "id":
$result = mysql_query("SELECT * FROM personnel",$db); echo "<TABLE BORDER=2>"; echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Options</B></TR>"; while ($myrow = mysql_fetch_array($result)) { echo "<TR><TD>".$myrow["firstname"]." ".$myrow["lastname"]."<TD>".$myrow["nick"]; echo "<TD><a href="view.php?id=".$myrow[id]."">View</a> "; echo "<a href="delete.php?id=".$myrow[id]."">Delete</a> "; echo "<a href="addedit.php?id=".$myrow[id]."">Edit</ a>"; } echo "</TABLE>"; ?> </HTML> Hellp? |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > problem retreving information from mySQL database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|