Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    199
    Thanks
    30
    Thanked 0 Times in 0 Posts

    A little bit of help with ++

    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:

    PHP Code:
            foreach(array_slice($imgdata0) 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.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
                    // make $pickey 1 outside of the loop else will be 1 for each step
            
    $pickey 1;
            foreach(
    array_slice($imgdata0) 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

  • Users who have thanked oesxyl for this post:

    Remix919 (05-01-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •