Page 1 of 5
Alphabetical sorting help....
Posted: Mon Feb 28, 2005 11:20 pm
by Smackie
alright i cant seem to get anywhere on this little alphabetical thing..
im looking for someone to help me code or even has a code that will work on what i need it for.... alright here is what i would like this code to do...
i would like for it to have like a place where users(already signed in) can post there poems on my site.. but the thing is i would like for it to have at the top of the pages
a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z
and for where when users submit there poems it will look at there names and have it alphabetical there first name (example: Adam would go to a and eve would go to e...... and Sam would go before Smackie) but thats what is stoping me

i been trying to do this for 2 weeks straight and cant seem to come up with anything i even look at the php manual to try and help me but i couldnt get anything done... please someone help me.....
Thank you in advance
Smackie
Posted: Mon Feb 28, 2005 11:25 pm
by feyd
and you have what done so far?
Posted: Mon Feb 28, 2005 11:28 pm
by smpdawg
Are you trying to do something similar to an address book that you see on some sites? You click a letter and then the screen refreshes with the names that start with that letter in alpabetical order.
Posted: Mon Feb 28, 2005 11:29 pm
by Smackie
nothing really

because i get a blank in the head and so i go to read the manual and still cant find anything about sorting alphabetical that would help me out or anything unless someone is just hiding it on me.....
Posted: Mon Feb 28, 2005 11:30 pm
by Smackie
yeah something like that yeah...
Posted: Mon Feb 28, 2005 11:31 pm
by smpdawg
Can we assume the user list is in a database? If so, what fields and tables are related to it? Have you written any code so far? Post a fragment, it will make it easier.
Posted: Mon Feb 28, 2005 11:33 pm
by feyd
typically it'd be like
Code: Select all
SELECT * FROM `users` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`
I believe we've discussed this before.. with you.
Posted: Mon Feb 28, 2005 11:35 pm
by Smackie
all i got really is the login script really thats it and yes they will be in a db as well..
Posted: Mon Feb 28, 2005 11:37 pm
by Smackie
no all you discussed about this with me was just to read the php manual which didnt help one bit
Posted: Mon Feb 28, 2005 11:53 pm
by smpdawg
Let me ask, and I am not trying to be rude, how much experience do you have with PHP and MySQL? I want to know so I can figure out how to answer your questions.
Posted: Mon Feb 28, 2005 11:55 pm
by Smackie
well not much i mean i learned from a friend well he tought me some of the basics before he got into a car wreck that ended his life but every since then i been trying to learn up on it and well only thing i really made by myself was a login script and a few other things.. so im somewhat of a newbie at it
Posted: Mon Feb 28, 2005 11:57 pm
by smpdawg
Sorry to hear about your friend. Thanks for the honest answer. Some people are afraid to say they are new, always have the courage to be honest. Let me think about it for a little bit and I will post some code and walk you through it.
Posted: Mon Feb 28, 2005 11:59 pm
by Smackie
well im not other people im straight up forward with my stuff lol i dont hide anything.. but alright cool and thank you very much... i started out with html i really good with html i been working with html for about 2 years now..... and i know alil bit of php and javascript... thats about it...
Posted: Tue Mar 01, 2005 1:08 am
by smpdawg
I wrote this quickly but it ought to work enough to give you a place to start. Make sure to replace the DB specific stuff with your own.
Code: Select all
<?php
// This function makes the alphabetic list which the links.
function drawAddressList() {
$seperator = "-";
// Loop through all 26 characters.
for ($i = 1; $i <= 26; $i++) {
$letter = chr($i + 64);
echo $seperator . "<a href='{$_SERVERї'PHP_SELF']}?letter={$letter}'>{$letter}</a>";
}
echo $seperator . '<br />';
}
// This function gets a parameter or the default.
function getParm($VariableName, $Default = '') {
return (isset($_GETї$VariableName])) ? $_GETї$VariableName] : $Default;
}
drawAddressList();
// Connect to MySQL - use your user name and password.
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Connects to the database that has the user table.
$db_selected = mysql_select_db('mysql_db', $link);
if (!$db_selected) {
die ('Can''t use table : ' . mysql_error());
} else {
$letter = getParm('letter');
if ($letter != '') {
$letter_query = "SELECT * FROM `users` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`";
$letter_result = mysql_query($letter_query);
if ($letter_result != false) {
while ($letter_row = mysql_fetch_assoc($letter_result)) {
// Do something in here with the rows you get.
// Maybe use the information from the user table to fill another recordset with the poems.
}
}
}
}
?>
Posted: Tue Mar 01, 2005 1:21 am
by Smackie
Thank you so much you have been helpful i would have probably pulled out my hair by the time i got half of that down lol but thank you again....
Smackie