Page 1 of 1

Problem with selecting the right row in a mysql database

Posted: Sun Dec 19, 2010 7:32 am
by izeqb
Hi everyone...

I'm still fairly new to PHP coding, so please, be gentle ;)

I have a database (MySQL) and I want to use a php script to search the database for a term (using stristr) store the ID in a variable and then go and extract data from database, based on the ID from before... (hope that made any sense)...

This is what I've got:

Code: Select all

			
$result = mysql_query("SELECT * FROM data");

while ($row = mysql_fetch_array($result)) 
		{   
			$data[] 	= $row[0];
			$kw[] 		= $row['kw'];
			$id[] 		= $row['id'];
			$url[] 		= $row['redurl'];
		}
						
foreach ($kw as $num=>$kw)
		{
			if (stristr($term, $kw))
		{
			$dbid 		= $num + 1;	
                }
}

echo $dbid


As of now it works fine, as long as I don't delete any rows in the database. Because, for some reason, it always select the ID of the row, just above/before the row where $kw and $term match.

Hope you guys understand what I'm talking about and hope you can help :)