Jump to content

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.