Page 1 of 1
getting data from database in alphabetically
Posted: Sun Mar 06, 2005 7:09 pm
by Smackie
Alright im looking for away to search the database for users first letter and put them on a webpage ... like say you got 5 different people posted something but you dont want it all being right there.. but i know you guys are going to get confused so im going to try and break it down for you all.
i want a script or something that when someone posts a poem it will create a username on the letter of the first name
(example: if someone uses Smackie there user name will go under S and will make a link using there username and it will post there poem in that link and every time he makes a new poem it will insert it in the same link but right under the the old poem....) if you can help me please post in here or hit me up on Aim, msn, or yahoo.......... Thank you in advanced
Smackie
Posted: Sun Mar 06, 2005 7:21 pm
by timvw
so all you need is a table poems and a table poets..
and then everytime a poem is posted you also store the poet_id...
and then you generate a page that accepts the first letter.... and then you search like:
select *
from poets inner join poems using (poet_id)
where poets.name like '$firstletter%'
and you're done.
Posted: Sun Mar 06, 2005 7:28 pm
by Smackie
easier said then done lol see i already got tabes set up but i guess i can redo them thats not hard but making the script is the hard part

lol here is the page i would like this script to work on/with
http://www.hauntedgraveyard.net/Poetry/ ... /index.php
Posted: Sun Mar 06, 2005 7:31 pm
by Burrito
As Tim said, just set up two tables that link to each other by the poet's id. The only thing I might add to his query to obtain the results you're after is to add an order by clause to sort the poet's names alphabetically.
feel free to add me up on MSN if you want some help.
Burr
Posted: Mon Mar 07, 2005 1:18 am
by infolock
Posted: Mon Mar 07, 2005 1:24 am
by Smackie
i already got that done

lol im now trying to find a way to add a link to it where when a user wants to look at someones poem or poems they just click on a name... but for some reason i cant find away to do that.....
Posted: Mon Mar 07, 2005 1:43 am
by Smackie
here is a link to show you the code so someone can help me
http://www.hauntedgraveyard.net/Poetry/script
Posted: Mon Mar 07, 2005 1:44 am
by feyd
rough example
Code: Select all
<?php
$user = (isset($_GETї'user']) ? mysql_escape_string(trim($_GETї'user'])) : '');
$query = mysql_query('SELECT * FROM `users`, `poems` WHERE `poems`.`userid` = `user`.`userid`') or die(mysql_error());
if(!$query || mysql_num_rows($query) < 1)
{
die('Unknown user or no poems in database.');
}
// display loop
?>
Posted: Mon Mar 07, 2005 1:45 am
by s.dot
Code: Select all
<? $sql = "SELECT poetname FROM poets WHERE poetid = '$poetid'";
$query = mysql_query($sql);
while($array = mysql_fetch_array($query)) { ?>
<a href="showpoems.php?poetid=<? echo $poetid; ?>"><? echo $arrayї'poetname']; ?></a><BR><? } ?>
With poetid coming from the URL.
Posted: Mon Mar 07, 2005 2:04 am
by Smackie
neither one of them works

here are the errors i get
from feyd script
Table 'haunted_poetry.users' doesn't exist
from scrotaye script
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/haunted/public_html/Poetry/poems.php on line 49
Posted: Mon Mar 07, 2005 2:22 am
by feyd
Didn't I mention "rough example" in my post?

That means you have to change the code to fit your table/database whatever..
Posted: Mon Mar 07, 2005 2:26 am
by Smackie
and thats what i did and still came out looking like that... or something like that....