Poetry help again

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!

Moderator: General Moderators

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Poetry help again

Post by Smackie »

for some reason my script will throw out all the users name at the beginning which i want it just show the alphabet :S but here is where i think the problem is at

Code: Select all

$sql = mysql_query("SELECT * FROM users WHERE user_name like '$letter%'"); 
while ($row = mysql_fetch_array($sql)) {
but here is the script for it

Code: Select all

<?php
echo '<center>';

// 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']}?pages=letter&letter={$letter}'><font class=\"txt\">{$letter}</font></a>"; 
} 
echo $seperator . '<br />'; 
} 

// This function gets a parameter or the default. 
function getParm($VariableName, $Default = '') { 
return (isset($_GET[$VariableName])) ? $_GET[$VariableName] : $Default; 
} 

drawAddressList(); 

echo '<br>';

$letter = $_REQUEST['letter'];

$sql = mysql_query("SELECT * FROM users WHERE user_name like '$letter%'"); 
while ($row = mysql_fetch_array($sql)) { 

                echo '<a href="index.php?pages=data&user_name='.$row['user_name'].'"><font class=\"txt"\ color=\"red"\>'.$row['user_name'].'</font></a><br>';

} 

echo '</center>';
?>

Thank you
Smackie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would guess $letter isn't being set. What does echoing the query string show?

[edit] damned fingers
Last edited by feyd on Thu Aug 25, 2005 9:42 am, edited 1 time in total.
airton
Forum Newbie
Posts: 2
Joined: Thu Aug 25, 2005 9:11 am

Post by airton »

Try:
SELECT * FROM users WHERE user_name like '". $_REQUEST["letter"] ."%'
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

you mean

Code: Select all

echo '<a href="index.php?pages=data&user_name='.$row['user_name'].'"><font class=\"txt"\ color=\"red"\>'.$row['user_name'].'</font></a><br>';
that is so when a letter is selected it shows the users under each letter like if you selected S it would show Smack and every other user that name begins with S
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Yeah it looks like the first time through, no letter has been set so its a query without restriction. Probably add a

Code: Select all

if (isset($_REQUEST["letter"])) {
guard statement around the bottom portion of the script.
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

Thank you that worked :)
Post Reply