...

View Full Version : A little bit of help with ++



Remix919
04-30-2011, 05:22 PM
Hey, I'm importing a bunch of pictures into a database and I want the first pic imported to have the $pickey of 1 and the second 2 and so forth. Here is my code:


foreach(array_slice($imgdata, 0) as $key=>$value) {
$pickey = 1;
$pickey++;
$url = $value;
$fname = basename("$url");
$destination = "/home/autolib/public_html/files/listing_orig_$fname";
copyemz ($url, $destination);
echo "$url - $fname <a href=http://autolibrium.com/files/listing_orig_$fname>check</a><br><br>";
//copy ("$url","/home/autolib/public_html/files/listing_orig_$fname");
$imagephoto = new SimpleImage();
$imagephoto->load($destination);
$imagephoto->resize(550,370);
$imagephoto->save("/home/autolib/public_html/files/listing_photo_$fname");
$imagephoto->resize(106,80);
$imagephoto->save("/home/autolib/public_html/files/listing_thumbnail_$fname");
mysql_query("INSERT INTO fl_listing_photos (ID, Listing_ID, Position, Photo, Thumbnail, Original) VALUES ('','$newlisting[ID]','$pickey','listing_photo_$fname','listing_thumbnail_$fname','listing_orig_$fname')");
}

Could someone let me know what I'm doing wrong because it keeps showing the Position as 0 instead of the $pickey number.

oesxyl
04-30-2011, 05:35 PM
// make $pickey 1 outside of the loop else will be 1 for each step
$pickey = 1;
foreach(array_slice($imgdata, 0) as $key=>$value) {
$url = $value;
$fname = basename("$url");
$destination = "/home/autolib/public_html/files/listing_orig_$fname";
copyemz ($url, $destination);
echo "$url - $fname <a href=http://autolibrium.com/files/listing_orig_$fname>check</a><br><br>";
//copy ("$url","/home/autolib/public_html/files/listing_orig_$fname");
$imagephoto = new SimpleImage();
$imagephoto->load($destination);
$imagephoto->resize(550,370);
$imagephoto->save("/home/autolib/public_html/files/listing_photo_$fname");
$imagephoto->resize(106,80);
$imagephoto->save("/home/autolib/public_html/files/listing_thumbnail_$fname");
// change the query this way and check result
$result = mysql_query("INSERT INTO fl_listing_photos (ID, Listing_ID, Position, Photo, Thumbnail, Original) VALUES ('','".$newlisting[ID]."','".$pickey."','listing_photo_".$fname."','listing_thumbnail_".$fname."','listing_orig_".$fname."')");
if(!$result){
print '<pre>'.mysql_error().'</pre>';
}
// increment $pickey for next image
$pickey++;
}

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum