getting data from database in alphabetically
Moderator: General Moderators
getting data from database in alphabetically
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
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
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.
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.
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
http://www.hauntedgraveyard.net/Poetry/ ... /index.php
here is a link to show you the code so someone can help me
http://www.hauntedgraveyard.net/Poetry/script
http://www.hauntedgraveyard.net/Poetry/script
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
?>
Last edited by feyd on Mon Mar 07, 2005 1:45 am, edited 1 time in total.
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><? } ?>