Loop exits prematurely in PHP

I want to create a loop to insert multiple records as it is executed. The goal is to easily create a complete database for testing purposes. Below is a loop I wrote, however the problem is that the loop exits due to premature stopping around 30 something.

$i = 0;
$numberOfRecords = 100;
$uploadedBy = "guest";
$uploadedWhen = date("Ymd");
$picture = "image";
$alt = "lorum ipsum";
$additionalInfo = "hello world";

set_time_limit(0);
while($i <= $numberOfRecords){
    $varName = 'guest'.$i;
    mysql_query("INSERT INTO images(id, uploadedBy, uploadedWhen, picture, alt, additionalInfo) 
        VALUES ('$i', '$varName', '$uploadedWhen', 'pictures/$picture', '$alt', '$additionalInfo')")        OR DIE("something died");
    echo $i;
    $i++;
}

      

so the question boils down to: Why is my code going out of 30-40 lines (currently the code is adding 2 loops to the loop on every update)?
thanks for the answers in advance.
NOTE. I know I shouldn't be using mysql_query, but this is just a hastily written draft that will undergo some tweaking after the looping problem is resolved. ^^

EDIT: clarification; the code runs for several iterations and then moves on to the OR DIE statement.
EDIT2: Removing the OR DIE statement solved the loop problems, VERY interesting is that entry 42 has the value $ i when the value is 0; if anyone wants to explain I would appreciate it.

+3


source to share


1 answer


  • Using id as an integer in a table

$ query = sprintf ("INSERT INTO test.images (id, uploadedBy, uploadedWhen, picture, alt, more info) VALUES ('% s','% s', '% s','% s', '% s ','% s ​​') ", $ i, $ varName, $ uploadedWhen,' pictures /'.$ picture, $ alt, $ AdditionalInfo); $ result = mysql_query ($ query) or die ("dies");



  1. Using id as varchar

you can use the source code.

0


source







All Articles