While loop's issue

Ok, so i am working on adding getting and adding multiple data at one time. I have a form generated with data (if a hen has laid, and the date) so i am setting some things so i can start to add the data to the database after words. all goes fine and dandy until i work with while loops. I must admit i have never worked with while loops but think they should not be much different than foreach()

here’s the full list

while ( $i <= $totalHens) {
			$henLaid.$i = post('hen_'.$i.'_laid');
			$henDateLaid.$i = post('hen_'.$i.'_date');
			$henId.$i = post('hen_id'.$i);
			if($henLaid.$i == 'laid'){
				$query .= "($henDateLaid.$i,$henId.$i)";			
			}
			$i++;
		}

here’s the full function

$totalHens = post('henCount');
		$i = post('startAt');
		$query = "INSERT INTO eggs(dateLaid,laidBy) VALUES";

		while ( $i <= $totalHens) {
			$henLaid.$i = post('hen_'.$i.'_laid');
			$henDateLaid.$i = post('hen_'.$i.'_date');
			$henId.$i = post('hen_id'.$i);
			if($henLaid.$i == 'laid'){
				$query .= "($henDateLaid.$i,$henId.$i)";			
			}
			$i++;
		}
		$Insert = $db->rawQuery($query);

and i have tested it. And it is not building the query , so to me that means it is not retrieving the data. But i am not sure.

Try:


               $query .= "(" . {$henDateLaid.$i} .",". {$henId.$i} . ")";  

echo out $query to see what the string contains exactly.

Thanks cups. That did not help, but i appercitate it. I did echo $query before and after using your version and all i ever got was

INSERT INTO eggs(dateLaid,laidBy) VALUES

GAaarch! No I take that back, that does not work!

I mean, the variable names will just keep overwriting themselves at each iteration so it could be written as


       while ( $i <= $totalHens) { 
            $henLaid = post('hen_'.$i.'_laid'); 
            $henDateLaid = post('hen_'.$i.'_date'); 
            $henId = post('hen_id'.$i); 
            if($henLaid == 'laid'){ 
                $query .= "('$henDateLaid',$henId) ";             
            } 
            $i++; 
        } 

echo $query;

** I guess the date is a date field, if it is you need to quote it with single quotes. If its a unix timestamp then just rm the quotes.