Page 1 of 1

Loop does thing once only

Posted: Mon Mar 02, 2009 1:50 pm
by malikov
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi,

I've been banging my head all day and I can't figure it out.

Code: Select all

$find = strip_tags($find); 
$find = trim($find); 
$find = strtoupper($find); 
 
    $data = mysql_query("SELECT * FROM profiles"); 
    while ($ss1 = mysql_fetch_array( $data ))
    {$ss3=$ss1['keywords']; $ss4=(explode(",",$ss3));
 
for ($x=0; $x<count($ss4); $x++){
             
$ss5=strip_tags($ss4[$x]);
$ss5=trim($ss4[$x]);
$ss5=strtoupper($ss4[$x]);
 
 if ($find==$ss5){ $profile=$ss1['name']; $pro_lvl=$ss1['prolvl'];
    $query=("insert into search(profile,pro_lvl,id) values ('$profile','$pro_lvl','$id')");
    $result = mysql_query($query);
}}}

It's supposed to insert all matches into table, but it only does if the first object ([0]) matches.
If it's [3] loop doesn't see it.


Please help ASAP.


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Loop does thing once only

Posted: Mon Mar 02, 2009 2:01 pm
by php_east
i think you want

$ss5=strip_tags($ss4[$x]);
$ss5=trim($ss5);
$ss5=strtoupper($ss5);

Re: Loop does thing once only

Posted: Mon Mar 02, 2009 2:21 pm
by malikov
php_east, you are a mind savior. I've been looking at this for hours, going mad. Thank you very much.

Re: Loop does thing once only

Posted: Mon Mar 02, 2009 2:57 pm
by php_east
send me a beer, send me a beer, quick ! ... :drunk:

Re: Loop does thing once only

Posted: Tue Mar 03, 2009 5:26 am
by josh
I guess we're starting to learn the difference between syntax & semantics ;-) Always use names that are obvious.