Dragen Posted April 19, 2007 Share Posted April 19, 2007 Hi, I've got this code, which gets the names of all the data from a table where the category equals $category. It's ordered by name. How do I get it so that it only outputs the results where name starts with a certain letter? for example.. only show results like: apple allan but not bob cod zebra here's my code <?php $sql = "SELECT * FROM downloads WHERE category = '$category' ORDER BY name DESC"; // finds the newest 2 items from $dispcategory if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo $row['name'] . "<br />"; } }else{ echo "unavailable"; } }else{ echo "Query failed<br />$sql<br />".mysql_error()."</td>\n"; } ?> Thanks Link to comment https://forums.phpfreaks.com/topic/47780-solved-output-names-beginning-with-certain-letters/ Share on other sites More sharing options...
Barand Posted April 19, 2007 Share Posted April 19, 2007 $initial = 'a'; $sql = "SELECT * FROM downloads WHERE category = '$category' AND name LIKE '$initial%' ORDER BY name DESC"; Link to comment https://forums.phpfreaks.com/topic/47780-solved-output-names-beginning-with-certain-letters/#findComment-233450 Share on other sites More sharing options...
Dragen Posted April 19, 2007 Author Share Posted April 19, 2007 Thanks! I'm actually doing it differently and just displaying them alphabetically now, instead of in seperate letter sections. Thanks anyway! Link to comment https://forums.phpfreaks.com/topic/47780-solved-output-names-beginning-with-certain-letters/#findComment-233460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.