MDanz Posted March 20, 2010 Share Posted March 20, 2010 in a cell in mysql i have tree, car, bus, dog, apple, ocean, tire. now i'd like to query only the words beginning with the letter T. So it should echo tree and tire. this hasn't been successful; <?php mysql_connect("localhost", "Master", "pword"); mysql_select_db("db"); $letter = "t"; $user =mysql_query("SELECT * FROM Stacks WHERE keywords REGEXP '^$letter' ORDER BY keywords ")or die (mysql_error()); while($rowz = mysql_fetch_array($user)){ $keyword = $rowz['keywords']; echo $keyword; } ?> it just displays "tree, car, bus, dog, apple, ocean, tire". when i want just the words beginning with t. Link to comment https://forums.phpfreaks.com/topic/195937-help-exploding-mysql-result/ Share on other sites More sharing options...
teamatomic Posted March 20, 2010 Share Posted March 20, 2010 $keyword='tree, car, bus, dog, apple, ocean, tire'; $letter='t'; $words=explode(",",$keyword); foreach($words as $word) { $word=trim($word); $first = substr("$word", 0,1); if($letter==$first) echo "$word<br>"; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/195937-help-exploding-mysql-result/#findComment-1029214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.