Jump to content

Why doesnt this code work? :(


dominod

Recommended Posts

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

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

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 :P 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++;
}

 

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 :P 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']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.