MDanz Posted February 6, 2010 Share Posted February 6, 2010 The cell keywords in mysql has multiple keywords in it. This is just one cell. How do i list the keywords of this cell separately in an index? Below doesn't list them separately, it takes the first letter of the entry in the cell and displays all the keywords(grouped). Any help greatly appreciated. <?php mysql_connect("localhost", "master", "pword"); mysql_select_db("db"); $letter = htmlentities($_GET['search']); $user = mysql_query("SELECT * FROM Stacks WHERE keywords LIKE '$letter%' ORDER BY keywords")or die (mysql_error()); while($rowz = mysql_fetch_array($user)){ $keyword = $rowz['keywords']; $bad = mysql_query("SELECT * FROM Stacks WHERE keywords LIKE '$letter%' ORDER BY keywords")or die (mysql_error()); $num_rows = mysql_num_rows($bad)or die (mysql_error()); } if ($num_rows == 0) { echo "<font face='Courier New' font size=18px font color=#FF9900>$letter</font><br /><br />"; echo "<font face='Courier New' font size=3px font color=#FBB917>No Stacks</font><br>"; } else { echo "<font face='Courier New' font size=18px font color=#FF9900>$letter</font><br /><br />"; echo "<font face='Courier New' font size=3px font color=#FBB917><a href='stack.php?search=$keyword&submit=Go!' style='text-decoration: none';>$keyword</a></font><br>"; } ?> how can i change the query to only select the keywords that begin with $letter in the one cell in mysql? e.g. $letter= 'a' and in the one cell in mysql it has keywords ... apple, bananna, etc. it should only list apple. how? Link to comment https://forums.phpfreaks.com/topic/191121-help-with-this-code/ Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 Why have you got multiple keywords in one field? Link to comment https://forums.phpfreaks.com/topic/191121-help-with-this-code/#findComment-1007753 Share on other sites More sharing options...
MDanz Posted February 6, 2010 Author Share Posted February 6, 2010 when i get an external websites meta tags, their keywords go into one field. Link to comment https://forums.phpfreaks.com/topic/191121-help-with-this-code/#findComment-1007754 Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 They shouldn't. Its a poor design and is always going to make searching the database more difficult. You should look into a one-to-many relationships design. Link to comment https://forums.phpfreaks.com/topic/191121-help-with-this-code/#findComment-1007755 Share on other sites More sharing options...
MDanz Posted February 6, 2010 Author Share Posted February 6, 2010 thx Link to comment https://forums.phpfreaks.com/topic/191121-help-with-this-code/#findComment-1007761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.