Jump to content

Looping ELSEIF command ?


dominod

Recommended Posts

Hi

 

I want to loop the following code with data from a MySql database:

 

elseif (wordsExist($search, array('$data1[$id]')))
{

$redir = "$data2[$id]";
}

 

I have the following code on top of the script:

 

include("connect.php");


$query =mysql_query("SELECT * FROM `engines`");
$i=0;
while($row = mysql_fetch_array($query ))
{
$data1[$i]=$row['name'];
$data2[$i]=$row['url'];
$i++;
}

 

Can anyone explain how to do this?

 

Thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/206521-looping-elseif-command/
Share on other sites

It would help if you provided an example of what $search contains and what the wordsExist() function does, because if you are just trying to find a matching row in a database table is it customary to simple query for that matching row instead of retrieving all the rows and trying to find a match -

 

"SELECT * FROM `engines` WHERE some_column = '$search'"

Let me try to explain what I am trying to do in another way..

 

I want the script to loop the following code for each row in the table:

 

elseif (wordsExist($search, array('$data1[$id]'))
{

        $redir = "$data2[$id]";
}

 

Meaning that if I have two rows in the table which is $data1=google / $data2=google.com AND $data1=bing / $data2=bing.com it will loop the code twice so it will look like this:

 

elseif (wordsExist($search, array('google'))
{

        $redir = "google.com";
}


elseif (wordsExist($search, array('bing'))
{

        $redir = "bing.com";
}

 

$search is by the way the value of a form field.

 

Thanks for your time :)

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.