dominod Posted July 2, 2010 Share Posted July 2, 2010 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 More sharing options...
PFMaBiSmAd Posted July 2, 2010 Share Posted July 2, 2010 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'" Link to comment https://forums.phpfreaks.com/topic/206521-looping-elseif-command/#findComment-1080288 Share on other sites More sharing options...
dominod Posted July 2, 2010 Author Share Posted July 2, 2010 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 Link to comment https://forums.phpfreaks.com/topic/206521-looping-elseif-command/#findComment-1080309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.