Problem with a loop

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

Problem with a loop

Post 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
Last edited by will83 on Mon Jan 09, 2006 7:30 am, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I only see one loop...?

Have you tried to echo out the query?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

Post 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
Post Reply