dominod Posted July 4, 2010 Share Posted July 4, 2010 I dont get this code to work ... Anybody knows what I am doing wrong? include("connect.php"); $query =mysql_query("SELECT * FROM engines"); $numrows = mysql_num_rows($query); while ($row = mysql_fetch_array($query) { $name[$i]=$row['name']; $url[$i]=$row['url']; $searchurl[$i]=$row['searchurl']; $keyword[$i]=$row['keyword']; $i++; } function wordsExist(&$string, $words) { foreach($words as &$word) { if(stripos($string, $word) !== false) { return true; } } return false; } if (wordsExist($search, array($keyword[$id]))) { $redir = "http://wedidit.com"; } when I use a actual word instead of a string in the following code it works .. (changed $keyword[$id] to 'keyword') if (wordsExist($search, array('keyword'))) { $redir = "http://wedidit.com"; } What I am trying to do is to make it trigger a certian redirect when it finds a certain word from the database. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/206717-why-doesnt-this-code-work/ Share on other sites More sharing options...
rwwd Posted July 4, 2010 Share Posted July 4, 2010 Hi there, You haven't set $i to a default state, so you can't increment something that isn't declared, error_reporting(E_ALL) would/should have flagged that up So:- include("connect.php"); $query =mysql_query("SELECT * FROM engines"); $numrows = mysql_num_rows($query); $i = "0"; while ($row = mysql_fetch_array($query) { $name[$i]=$row['name']; $url[$i]=$row['url']; $searchurl[$i]=$row['searchurl']; $keyword[$i]=$row['keyword']; $i++; } That will get you started, also where are you getting $id from, unless it's set somewhere else in the script, I cant see it in the example code you have posted.. Rw Link to comment https://forums.phpfreaks.com/topic/206717-why-doesnt-this-code-work/#findComment-1081080 Share on other sites More sharing options...
dominod Posted July 4, 2010 Author Share Posted July 4, 2010 Thanks for that quick answer I added that line of code but it still wont work :/ It just takes me to a blank page . . EDIT: Dont know where I am getting $id from Sorry I am a newbie .. . Will this be correct? while ($row = mysql_fetch_array($query) { $id=$row['id']; $name[$i]=$row['name']; $url[$i]=$row['url']; $searchurl[$i]=$row['searchurl']; $keyword[$i]=$row['keyword']; $i++; } Link to comment https://forums.phpfreaks.com/topic/206717-why-doesnt-this-code-work/#findComment-1081084 Share on other sites More sharing options...
GetFreaky Posted July 5, 2010 Share Posted July 5, 2010 Thanks for that quick answer I added that line of code but it still wont work :/ It just takes me to a blank page . . EDIT: Dont know where I am getting $id from Sorry I am a newbie .. . Will this be correct? while ($row = mysql_fetch_array($query) { $id=$row['id']; $name[$i]=$row['name']; $url[$i]=$row['url']; $searchurl[$i]=$row['searchurl']; $keyword[$i]=$row['keyword']; $i++; } What do you mean? Your getting $id from the sql query.... $row['id'] Link to comment https://forums.phpfreaks.com/topic/206717-why-doesnt-this-code-work/#findComment-1081125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.