RE: [PHP] selecting first character from a MySQL table
| From: | Jay Blanchard | Date: | Wed, 04 Jun 2003 11:58:29 +0000 |
| Subject: | RE: [PHP] selecting first character from a MySQL table | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-150136@lists.php.net to get a copy of this message | ||
How about a substring comparison? Select all from your database and then
loop through using an array of the alphabet.
[NOT TESTED]
$alpha_array = array("A","B","C", ....);
$alpha_count = count($alpha_array);
for($i=0; $i<$alpha_count; $i++){
$sql = "SELECT name FROM table WHERE LEFT(name, 1) = '" .
$alpha_array[$i] . "' ";
$result = mysql_query($sql, $yourconnection);
while($row = mysql_fetch_object($result)){
print($result->name . "\n");
}
}
[/NOT TESTED]
HTH!
Jay