Hi,
I have a page on my site which is entirely a long list of <a href=> for a selection of midi files.
I'm constantly adding to the list and it is not practical to keep finding the correct place in the list to maintain an alphabetical order.
I know you can sort arrays but is there any way I can sort my list?
I figured I could create an array which contains all of my links and then sort the array but I wasn't sure how to implement it so that each value in the array is a link or how to echo the sorted list back out onto the page in the form of links.
Sorry it probably seems like an obvious answer but I'm new to PHP.
Thanks
Sorting a list
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Thanks.
I'll have go but I know nothing at all about mysql... I can't even work out how to connect to the server my file are on LOL.
Erm... if anyone else has any ideas how to just contain all the links inside a variable, then sort the variable and echo it back out onto the page please let me know.
I admit mySql would be better (especially since I could include a search page) but I just don't know where to start. I'm not running the server.. it's my university's server and I've checked with phpinfo() and they are using mysql. It gives this info about it:
Thanks
I'll have go but I know nothing at all about mysql... I can't even work out how to connect to the server my file are on LOL.
Erm... if anyone else has any ideas how to just contain all the links inside a variable, then sort the variable and echo it back out onto the page please let me know.
I admit mySql would be better (especially since I could include a search page) but I just don't know where to start. I'm not running the server.. it's my university's server and I've checked with phpinfo() and they are using mysql. It gives this info about it:
Does this give any clues how to create a db and connect to it etc? What do I need to do.. I've heard that you use the command line? I downloaded phpMyAdmin and put it in my web space but when I open it I get an errorMySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 4.0.12
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_INCLUDE -I/usr/local/mysql/mysql-standard-4.0.12-sun-solaris2.8-sparc/include
MYSQL_LIBS -L/usr/local/mysql/mysql-standard-4.0.12-sun-solaris2.8-sparc/lib -lmysqlclient
And when I try going to config.inc.php I just get a blank page.phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in config.inc.php and make sure that they correspond to the information given by the administrator of the MySQL server.
Error
MySQL said:
#2002 - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[Documentation]
Thanks
-
aleigh
- Forum Commoner
- Posts: 26
- Joined: Thu Mar 25, 2004 11:06 am
- Location: Midwestern United States
- Contact:
Re: Sorting a list
I would look at putting the URLs into an array like you mentioned, and then you want to use something like sort() to sort it.d11wtq wrote:Hi,
I have a page on my site which is entirely a long list of <a href=> for a selection of midi files.
I'm constantly adding to the list and it is not practical to keep finding the correct place in the list to maintain an alphabetical order.
I know you can sort arrays but is there any way I can sort my list?
I figured I could create an array which contains all of my links and then sort the array but I wasn't sure how to implement it so that each value in the array is a link or how to echo the sorted list back out onto the page in the form of links.
Sorry it probably seems like an obvious answer but I'm new to PHP.
Thanks
If you have song title and filename, though, I would do it like this;
$files['Some Song']='somesong.mid';
$files['Other Song']='othersing.mid';
$files['A Song']='zsong.mod';
ksort($files);
foreach($files as $n => $v) {
print '<A HREF="'.$v.'">'.$n.'</A><P>';
}
If you want to sort on the file-names rather than the titles use asort() instead.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia