RE: [PHP] insert loop logic

From: Date: Wed, 04 Jun 2003 21:34:27 +0000
Subject: RE: [PHP] insert loop logic
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-150274@lists.php.net to get a copy of this message
> When i get these values I want to enter them into the database but > 1)I should enter only the first 5 (and ignore the rest) into the database > 2)it has to enter 1 record for every every "id" picked > eg: > if id[1], id[2],id[3] and id[4] were picked it should enter this as 4 > differient records > > > How do i do this? I have tried using a for loop but somewhere the logic is > very very bad :-) and so i deleted the whole damn thing. <?php $count = 0; if (is_array($id)){ while( (list(,$val) = each($id)) && $count < 5){ $count++; $query = "INSERT INTO table () VALUES ('$val')"; mysql_query($query); } } ?> Obviously the query is not all there and needs fleshing out, I don't know what all you are inserting. I didn't really test, so it might have a bug or something.

« previous php.general (#150274) next »