Last 5 entries with php and mysql
Posted 03 July 2006 - 10:33 PM
i have a small question.
Im using a script that display all results in a DB and i can do some query.
i insert also date.
Now i need to know how can i display with a echo the last 5 posts into my DB using date. How can i do that?
Posted 03 July 2006 - 10:53 PM
SELECT * FROM table ORDER BY date DESC ?
Wouldn't this just show the last five entry's for the "table".
How would you do this for your whole database?
(check all your tables)
Posted 04 July 2006 - 05:19 AM
let's say you have 3 tables called
and in each table is date column. it doesn't matter if they are all named the same or not, as long as they are the same data type. but let's just say for the sake of clarity they are all named different:
and we want to choose the 5 most recent dates out of all 3 tables overall, right? okay so here we go:
(SELECT date1 FROM table1) UNION (SELECT date2 FROM table2) UNION (SELECT date3 FROM table3) ORDER BY date1 DESC LIMIT 5
okay so here's an explanation of what this does: this runs 3 seperate queries all at once. Then it merges all the data into one column. The column is named the same name as what is selected in the first query so since that is date1, the result will return your list with the column named date1. That is why we are ordering by date1 at the end.
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community
Posted 04 July 2006 - 10:59 AM
select * from table where date = 'daet here' limit 5
Posted 04 July 2006 - 11:14 AM
that what union does just joins all table fields as one.
((EMAIL CODE THAT WORKS))
((PAYPAL INTEGRATION THAT WORKS))
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users