This is a discussion on "[SOLVED] PHP Sorting" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP Sorting are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] PHP Sorting
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
[SOLVED] PHP Sorting
Hello once again,
I have the following code to sort a bunch of arrays:
1) Sort numerically 2) Sort alphabetically 3) Sort normally (the way it is in the script) Now, when clicked, the links will simply add "?sort=value" to the URL. The "value" is one of the three above. On my actual page (since the above names are an example) there is a list of 'downloadable' files that are, by default, listed in the order that they were posted (numerically by date - ex: July 10, August 23, October 17). Then, the second link is to sort them by their title (alphabetically by title - ex: File A, File B, File C). Finally, the last link will sort them by the name of the person that posted them (alphabetically by name - ex: Amanda, Mark, Ryan, Wendy). I am sure that I need more than the above code, and probably separate arrays for all three points, but I am not sure of how to do this since I am still new to php Any help would be much appreciated. Thanks, SWagner PS: If you do not quite get what I am asking, don't hesitate to ask.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
|
|
||||
|
Re: PHP Sorting
Is the list going to static, or dynamically read out of a database?
How long is the list going to be?
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: PHP Sorting
Well, at the moment, I have the list as static html. The problem is, it is not much of a list in terms of using <ul> or <ol>. I just have several divs, one after the other. The divs all have a unique id, so it might still work. But if you think it is better, I can make put each div into a <li> although I don't think that will correspond well with my stylesheet...
The list is going to have a maximum number of 100 items.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
||||
|
Re: PHP Sorting
I would use a MySql database for this. Put your arrays into a database with the following fields (number,name,timestamp). Then you can just change the query to sort the items:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: PHP Sorting
Sorry about this: How do you create a MySQL Database. I have never done something like this...
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
|||
|
Re: PHP Sorting
I am not sure what hosting/xampp is, but if you're asking if my server has MySQL, then yes.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
||||
|
Re: PHP Sorting
Your server as in you have physical access to it or as in you have to upload to it?
If you are using the command prompt mysql. Type the following in:
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Last edited by alexgeek; Oct 18th, 2007 at 14:00. |
|
|||
|
Re: PHP Sorting
OK, hold on...
Let me tell you what the whole story is here: Within my website, there is a directory (secure/) which is password protected by .htaccess. In this directory, there is the page that contains the "list" of files that people have uploaded (index.php). The way people upload files is through another page in the secure/ directory (upload.php). This page uses php to transfer the uploaded files into a new folder inside secure/ (files/). OK so far? The files are called and output by index.php in the order that is determined by the "?sort=" value in the URL. Now, to be honest, I have no idea how to do any of this... So, I am going to need a lot of help Thanks, SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
||||
|
Re: PHP Sorting
When a file is uploaded and you move it to the secure folder, then you insert a new row into your database with the number and name of the file and the timestamp when it was uploaded. Then in index.php your code will look something like so:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: PHP Sorting
I don't want to annoy anyone here, but could someone give me the basic rundown for a MySQL Database, how it works, and how to create one? Honestly, I am really stumped
All I need is two codes: one to upload the files to a database through a form, and one to call the files from that database and display them in a list. Like I said, I have no idea whatsoever how to do this (don't get frustrated with me!). Thanks, SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help sorting an array | djeyewater | PHP Forum | 6 | Apr 18th, 2008 15:16 |
| [SOLVED] Array sorting | welshstew | Classic ASP | 6 | Nov 28th, 2007 16:45 |
| Sorting a PHP array | fallen_angel | PHP Forum | 3 | Apr 20th, 2007 22:18 |
| Need help sorting highscore - rsort() | mofle | PHP Forum | 2 | Apr 8th, 2007 09:41 |
| Mysql sorting problem.... | mills | Databases | 2 | Jul 26th, 2005 09:08 |