PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
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.....
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.
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.....
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.
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.
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
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.
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...
<?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.
}
}
}
}
?>
Last edited by smpdawg on Fri Mar 04, 2005 8:38 pm, edited 1 time in total.