Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I made a simple script that inserts data into my table from an array named $videos. The result is that I get a table with correct titles but the ID is repeated over and over in all rows that were inserted. The strange thing is that when I echo $id inside the loop I get the correct id's each time. for some reason it does not insert to the table the correct id's too.

This is my code:

     $page_counter = 0;
do{
    $videos = $bc->find("allVideos",array("page_number" => $page_counter,"page_size" => 10, "media_delivery" => "http"));    
    for ($movie_counter = 0; $movie_counter < count($videos); $movie_counter++){
       $name = $mysqli->escape_string($videos[$movie_counter]->name);
       $id = $videos[$movie_counter]->id;
       echo "ID " . $id . "<BR>";
       $mysqli->query("INSERT INTO bc_current2(id,title) VALUES('$id','$name')");


    }
    $page_counter++;
}
while (count($videos) == 10);

So for example if each time I get printed ID's: 1 , 2 , 3 ,4 ... In my table I see the same ID : 1 repeated in each row but the title is correct and not repeated.

share|improve this question
    
$videos[$movie_counter]->id; is probably a double indexed array – Mihai Dec 10 '13 at 15:19
    
What does that mean? – nimi Dec 10 '13 at 15:24
    
POST a print_r of $videos[$movie_counter] outside any loop and post it in your qeustion. – Mihai Dec 10 '13 at 15:26
    
I tried print_r($videos[$movie_counter]) after the last while... I get no result in this case – nimi Dec 10 '13 at 15:29
    
$movies_counter is created within the previous block, so it doesnt exist under the last while xD. print_r($videos[$movie_counter]) or var_dump($videos[$movie_counter]) on the place you echo it now, and make sure to do it either for just 1 movie, or that you keep track of what is posted when. – Viridis Dec 10 '13 at 16:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.