0

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.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by somedude3488
0

Your regular expression should be '^$letter.*' i think. It starts with a t and contains any number of any characters. Your current one will only match t

0

The best way is to use a keywords table. Then have another table to match a keyword to the proper stack (I am guessing since I don't know your setup). It would take more work but it would be easier to manage.

Edited by somedude3488: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.