Page 1 of 1

Problem with a loop

Posted: Sun Jan 08, 2006 6:21 pm
by will83
Hi,

Having a problem with the following;

Code: Select all

$last_id = mysql_insert_id();
	
$type_count = count($types);
	
for ($i=0; $i < $type_count; $i++) { 
		
$match = "";

if ($types[$i] == $featured[$i]) {
	$match = "y";
	}
					
	$q_add_types = "INSERT into company_ins (Id, company_id, ins_id, type_featured) VALUES ('', '$last_id', '$types [$i]', '$match')";
		mysql_query($q_add_types) or die(mysql_error());
}
Does anybody know why the insert query wont work with inner statement included.

Thanks

Will

Posted: Sun Jan 08, 2006 6:24 pm
by hawleyjr
I only see one loop...?

Have you tried to echo out the query?

Posted: Sun Jan 08, 2006 6:32 pm
by Zoxive
Does any of $types[], $featured[] match?

like hawleyjr said try printing it out, or take it out and just print something to make sure it works, it would also help if you posted more code, so we can see where featured comes from..

Edit: is the query supose to be in the if statement?

-NSF

Posted: Mon Jan 09, 2006 7:29 am
by will83
Yes sorry, only one loop.

It works when the inner parenthesis is removed.

I will try printing the outout and making sure there is out put and whether any mathces up, although it should do.

The $featured[] and $types[] come from a form on a previous page. A list of types of insurance are displayed with 2 checkboxes. One for user to select to include and the other to select if that type is to be featured.

I will have a play, thanks.

Will