Search SQL by first letter
Posted: Mon Feb 21, 2005 9:34 am
Hi,
I'm not very familure with splitting text strings, and though I have searched all over for a solution, I cannot seem to find one to fit what I am attempting.
I have a my_sql search query that looks like this:
When This page is visited there are three URL variables taking place.
BookID, ChapterID, and LetterID
Currently everything works great with only the BookID and ChapterID in place. Now I want to add functionality with the LetterID variable.
I want to display only the results where the first letter of table character column CNameL begins with the letter LetterID
for example, if this is a list in the database
Abbots
Ansle
Axle
Badrock
Bungstrum
Cunnel
and I sort it with LetterID = B
the result should display only
Badrock and Bungstrum.
What I feel I need to do is some how take the full list from the database, capture the first letter of that column and then pull entries from that list.
Am I close?
Thanks for any help you can give!
I'm not very familure with splitting text strings, and though I have searched all over for a solution, I cannot seem to find one to fit what I am attempting.
I have a my_sql search query that looks like this:
Code: Select all
mysql_select_db($database_lexicon, $lexicon);
$query_Characters = "SELECT * FROM `character` WHERE (BookID < '$GBookID') or (BookID = '$GBookID' AND ChapterID <= '$GChapterID') ORDER BY `CNameL` ASC";
$Characters = mysql_query($query_Characters, $lexicon) or die(mysql_error());
$row_Characters = mysql_fetch_assoc($Characters);
$totalRows_Characters = mysql_num_rows($Characters);BookID, ChapterID, and LetterID
Currently everything works great with only the BookID and ChapterID in place. Now I want to add functionality with the LetterID variable.
I want to display only the results where the first letter of table character column CNameL begins with the letter LetterID
for example, if this is a list in the database
Abbots
Ansle
Axle
Badrock
Bungstrum
Cunnel
and I sort it with LetterID = B
the result should display only
Badrock and Bungstrum.
What I feel I need to do is some how take the full list from the database, capture the first letter of that column and then pull entries from that list.
Am I close?
Thanks for any help you can give!