PDA

View Full Version : Array in MySQL used to find rows?



djlebarron
29 Nov 2008, 10:06 AM
I've got a need to insert mulitple town names into one MySQL field named "towns". I then need to access information in a query from all the rows that have certain town names. Not a combination of town names, but from a list of town names or just one town name. In other words, row A, field "towns" would have Buffalo, Youngstown, Pittsburgh. row B, field "towns" would have Atlanta, Philidelphia, Roanoke...etc. My query wants the information from field "Event" from all rows with Roanoke in the "towns" field. How should the array in "towns" appear in the dbase so I can query by Roanoke successfully?

I put simply

Atlanta, Philidelphia, Roanoke,

in the "towns" field, but my query won't recognize the single town Roanoke even when I use the "like" condition.

starfish
01 Dec 2008, 01:50 AM
hi
i just attempted to put up the data in the database as u told and
tried to get the row from the database that matches the specified string within the data in each row
sorry i don't got a solution through a query but
we may use php functions as shown below

$query="select towns, events from table";
$result=mysql_query($query) or die("Couldn't execute query :".mysql_error());
while($row=mysql_fetch_array($result))
{
$value="delhi";
if(strchr($row['data_value'],"delhi"))
{
echo $row['data_value'];
echo "-----------Match Found!!<br>";
}
else
{
echo "-----------No Match Found!!<br>";
}

we may fetch the value of string to be matched from the previous form (here i use "delhi") and further match accordingly
and perform further functions after it gets matched as per requirement
instead of just echo it
sorry if i misunderstood it