Looping ELSEIF command ?

Discussion in 'PHP' started by misterdh, Jul 2, 2010.

  1. #1
    Hi

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

    elseif (wordsExist($search, array('$data1[$id]')))
    {
    
    	$redir = "$data2[$id]";
    	}
    PHP:
    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++;
    }
    PHP:
    Can anyone explain how to do this?

    Thanks in advance :)
     
    misterdh, Jul 2, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    lukeg32, Jul 2, 2010 IP
  3. misterdh

    misterdh Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Okey but how can I loop it?

    I am trying to re-direct the page if it finds certain keywords in the text

    The keyword it need to find is in a mysql database.. The same is the redirect URL.
     
    misterdh, Jul 2, 2010 IP
  4. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #4
    
        $text = "long text with many words";
        $words_array = array("text","many");
        $words = explode(" ",$text);
        foreach($words as $word){
            if(in_array($word,$words_array)){
                redirect($word);// redirects to "text"
            }
        }
    
    PHP:
    If I understood you correctly.
     
    astrazone, Jul 4, 2010 IP