This is a discussion on "[SOLVED] PHP/MySQL Sorted Output" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP/MySQL Sorted Output are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] PHP/MySQL Sorted Output
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
[SOLVED] PHP/MySQL Sorted Output
Hello everyone,
I have a new problem that I'm sure you'll be able to help me with. On my site, there is a page on which a php script calls a mysql database and outputs a table, which is called "files". It's all working fine, but now I want to add a few more features. Above the php script, there are three links that can be used to sort the data in different ways. The links look like this:
So, the problem is, I can't seem to find a way to display all the data with one php script, in a way that "oddsection" and "evensection" alternate! I have the following php, but it's not very far:
http://www.domain.com/index.php?order=title And "title" would change to "author" if the user selected the 'sort by author' link above. "date" would not be used since it is the default and will be displayed in that order when this variable is not present in the url. So, like this in the php script:
The main idea is, the script places the data from the database into html code, and sorts the data according to the variable in the URL. Any help would be great! Thanks, Stuart
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Nov 21st, 2007 at 03:58. |
|
|
|
||||
|
Re: PHP/MySQL Sorted Output
I would let MySQL to the sorting and then just output what the query returns:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: PHP/MySQL Sorted Output
OK, all set. Now to the other problem. How to I make the php script output the data in the database in a way that the class element on the div alternates. Like this:
Thanks
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Nov 21st, 2007 at 16:56. |
|
||||
|
Re: PHP/MySQL Sorted Output
See if you can understand this. I hope my programming logic is right, I haven't tested this....:
See if you can do something with this code. Feel free to ask questions.
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: PHP/MySQL Sorted Output
You could set a variable to zero; if the variable is zero, set the class to even, else, set the class to odd; increment it with each "file"; if the variable equals 2, set it to zero.
|
|
|||
|
Re: PHP/MySQL Sorted Output
Great! I adjusted it a bit and I got what I wanted...
Thanks for all your help! Thread Solved
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Form output using mysql, search people name in specific category | basketmen | PHP Forum | 1 | Mar 24th, 2008 06:31 |
| [SOLVED] form output in CSS | dhossai | Web Page Design | 4 | Nov 6th, 2007 00:22 |
| [SOLVED] Reading output. | alexgeek | PHP Forum | 2 | Oct 30th, 2007 00:41 |