Jump to content

[SOLVED] Loop just ignores the string


dan17

Recommended Posts

Hi,

 

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

 

$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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/147622-solved-loop-just-ignores-the-string/
Share on other sites

You'll find people help you a lot more if your code is indented correctly and all of your braces line up. While I don't know what your problem is without seeing some sample data, I've added a two echo commands in so that you can see the value in find and the value it is being compared against ($ss5). Run this code and see the values printed and maybe that will shed some light on your problem.

 

$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]);

	echo $find."<br>";
	echo $ss5."<br><br>";

	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);
	}
}
}

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.