View Full Version : Display by letter
simjay
04-08-2007, 09:17 PM
example: $letter = a
<?
$sql = "SELECT * FROM name WHERE *****first letter = $letter *****";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
$name = $newArray['name'];
echo "$name *<br>";
}
?>
I am trying to make a script so i can display a list of name beging with the letter *.
Any help would be great.
iLLin
04-08-2007, 09:20 PM
$sql = "SELECT * FROM name WHERE first letter = '%".$letter/"';
That will return all results with the name that begins with "a";
simjay
04-08-2007, 09:25 PM
sorry but its not liking that?
simjay
04-08-2007, 09:27 PM
this is what i have
$sql = "SELECT * FROM user ORDER BY user_name WHERE user_name = '%".$letter/"'";
iLLin
04-08-2007, 09:28 PM
im sorry
$sql = "SELECT * FROM name WHERE first letter LIKE '%".$letter."';
Notice the LIKE
iLLin
04-08-2007, 09:28 PM
and the slash was a typo, should have been a period
simjay
04-08-2007, 09:31 PM
still not working sorry, are the speach marks right?
iLLin
04-08-2007, 09:33 PM
sql = "SELECT * FROM user WHERE user_name LIKE '%".$letter."' ORDER BY user_name";
simjay
04-08-2007, 09:38 PM
no work, lol im getting ready to give up with this, lol
iLLin
04-08-2007, 09:44 PM
Im sucking today
sql = "SELECT * FROM user WHERE user_name LIKE '".$letter."%' ORDER BY user_name";
The percent should be at the end.
simjay
04-09-2007, 04:52 AM
yay, lol
thank you so much
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.