Page 1 of 1

Poetry help again

Posted: Thu Aug 25, 2005 9:26 am
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

Posted: Thu Aug 25, 2005 9:34 am
by feyd
I would guess $letter isn't being set. What does echoing the query string show?

[edit] damned fingers

Posted: Thu Aug 25, 2005 9:38 am
by airton
Try:
SELECT * FROM users WHERE user_name like '". $_REQUEST["letter"] ."%'

Posted: Thu Aug 25, 2005 9:39 am
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

Posted: Thu Aug 25, 2005 9:41 am
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.

Posted: Thu Aug 25, 2005 11:58 am
by Smackie
Thank you that worked :)