thanxs that worked can you help me out with this also.
1) When it gets the data from the database how would i sort it by date in descending order (newest entry at top)
2) When status is 'New' change the row bgcolor to #FFDE84, when the status is 'Verified' or 'In' change the row bgcolor to #FF0000 and when the status is 'Ended' change the bgcolor to #D5D5D5.
3) How can i add pages at the bottom so it only shows 25 entries a page
Hi again i have done the sort by date one i just need help with these:-
2) When status is 'New' change the row bgcolor to #FFDE84, when the status is 'Verified' or 'In' change the row bgcolor to #FF0000 and when the status is 'Ended' change the bgcolor to #D5D5D5.
3) How can i add pages at the bottom so it only shows 25 entries a page
Glad you figured out your problems. I would suggest is to modify your query to the following.
SELECT date, name, id, title, status FROM table
instead of
SELECT * FROM table
If you are concerned about SPEED and OPTIMIZATION you never want to use a SELECT *. I know everyone does it and that's probably the reason many sites are typically slower and not optimized. A number 1 rule of being a DBA is to only bring back the data you need. If you are not using the additional fields don't return them. The database will run much faster and get less fragmented if you stop using SELECT *.
Glad you figured out your problems. I would suggest is to modify your query to the following.
SELECT date, name, id, title, status FROM table
instead of
SELECT * FROM table
If the only rows in the table are "date, name, id, title, status" then [select *] and [select date, name, id, title, status] will return the same data, so using [select *] would be fine in that occurance.
---
With regard to the paging - I can't write it all for you now, but here's what you need to do:
Change the Query to:
SELECT date, name, id, title, status FROM table Limit $start, 25;
Now all you need to do is set the $start variable and add some links at the bottom of your page with the anchor text "Next" and "Previous" and pass in the query string the appropriate $start value.
+ Make $start default to 0 if it is not set in the query string.
+ Make sure that you don't let $start get below 0.
+ Make sure that $start doesn't get above the maximum number of possible results.
If the only rows in the table are "date, name, id, title, status" then [select *] and [select date, name, id, title, status] will return the same data, so using [select *] would be fine in that occurance.
jg_v7n, IMO SELECT * is just lazy coding practise. If you do SELECT * the database needs to find out what fields are actually in the table before it can then select them all. By specifying the field names the database engine can use those names straight away rather than having to do an extra lookup. Even if the query is returning the "SAME" data. It's not always about the data it's mostly about performance and the additional use of DB resources.
The sad fact is that this bad situation is not immediately apparent. In a testing environment, the programmer may have, ahem, other priorities. During volume testing, the poor performance is noticed and if your organization does not do volume testing, you may not realize that SELECT * is bad for performance until the program goes live.
Sure it probably is lazy, I always name the rows unless I know that I want all available rows, in which case I use select * simply bacause it's quicker.
Either way I'm pretty sure that the effect is neglegable in comparison to actually returning the table data.
Thought I'd run a quick test (results inconclusive):
Nothing personal jg_v7n, but just out of curiousity how long have you been a dba?
You are correct that 1 user is NOT going to make a big difference. You will only start seeing a performance slowdown when you start having high traffic on the database. You know what, this conversation is starting to go off topic so I think I'll start my own thread to see what others think.
Microsft, Oracle, Sybase and MySQL all can't be wrong now can they?