|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
limit results from mySQL?
Hello:
I am new to PHP and trying to limit results from a mySQL query. basically I would like to know the best practice for doing somethign like this. I have a table in mySQL that I am trying to pull three fields from for items equal to or older than *today* limit the results to five and print those to the screen in a particular format. I thought I should use something like this: <?PHP (connection string) Select folderName, galleryName, entryDate from Gallery where entryDate <= *today?* limit 5 order by entryDate DESC; { echo "<a href=/galleries.php?folder=$folderName>$galleryName</a><br>" } ?> any advice would be greatly appreciated. I am not really sure but I think I need to loop? how do I do that? and also I am not sure about how to format the *today* so that it compares and also sorts. Thanks in advance. -- Todd |
|
#2
|
||||
|
||||
|
RE: limit results from mySQL?
The LIMIT clause should be after the ORDER BY clause.
After you do your query (via mysql_query), you will need to loop using one of: mysql_fetch_array, mysql_fetch_row, or mysql_fetch_assoc. If entryDate is a DATE field, using NOW() should work for *today*. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > limit results from mySQL? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|