Witam

Nie wiem jak to ugryzc. Mam taka funkcje:

  1. <?php
  2. function carUploadPhoto()
  3.    {
  4.    
  5.        global $mainframe, $option;
  6.        
  7.        $db =& JFactory::getDBO();
  8.        
  9.        //Handle image class
  10.        $image = new atompImage();
  11.  
  12.        //path to upload Dir
  13.        $uploadPath = JPATH_COMPONENT.DS.'uploads/offers/';
  14.    
  15.        
  16.            if (JRequest::get( 'post' ))
  17.            {
  18.            //Files array
  19.            $file = JRequest::getVar('image', null, 'files', 'array');
  20.            
  21.            //how many arrays
  22.            $sizeofarray = count($file);
  23.            
  24.            //loop arrays
  25.            for ($i = 0; $i < $sizeofarray; $i++)
  26.            {
  27.            
  28.            //create a new arrays suitable for upload
  29.            $newarray[$i] = array('name' => $file['name'][$i], 'type' => $file['type'][$i], 'tmp_name' => $file['tmp_name'][$i], 'error' => $file['error]'][$i], 'size' => $file['size'][$i]);
  30.            
  31.                //if arrays not empty process
  32.                if (!empty($newarray[$i]['name']))
  33.                {
  34.                //SET ALL CLASS METHODS
  35.                $image->setFiles($newarray[$i]);
  36.                $image->setImagePath($uploadPath);
  37.                $image->setMaxImageSize('100000');
  38.                $image->setAllowed(array('image/pjpeg','image/gif','image/jpeg','image/JPG','image/jpg'));
  39.                
  40.                if (!$image->check()) {
  41.                    
  42.                    $this->msg .= $image->getMessage();
  43.                    break;
  44.                
  45.                } else {
  46.                    
  47.                    $newarray[$i]['name'] = preg_replace("/[^a-zA-Z0-9.]/", "", strtolower($newarray[$i]['name']));
  48.                    
  49.                    //FILE IMAGE NAME
  50.                    $data['image'.$i] = $newarray[$i]['name'];
  51.            
  52.                    $row_img =& JTable::getInstance('car_ogloszenia_img', 'Table');
  53.  
  54.                    if (!$row_img->bind( $data )) { return JError::raiseWarning( 500, $row_img->getError() ); }
  55.                    if (!$row_img->store()) { JError::raiseError(500, $row_img->getError()); }
  56.            
  57.                    //GET INSERTED ID FOR NEW INSERTION
  58.                    $database =& JFactory::getDBO();
  59.                    $this->insertedID = $database->insertid();
  60.        
  61.                    //SET IMAGE NAME AND UPLOAD
  62.                    $image->setImageName($this->insertedID .'-'. $newarray[$i]['name'] );
  63.                    
  64.                    if ($image->upload()) {
  65.  
  66.                        $image->setThumbWidth('120');
  67.                        //CREATE THUMBNAILS
  68.                        $image->createThumb();
  69.                        $image->createLightBox();
  70.                        
  71.                    }
  72.                    
  73.                    $this->msg .= $image->getMessage();
  74.                    }
  75.                
  76.                } //EOF if empty
  77.            
  78.            } //EOF for
  79.        
  80.        } //EOF post
  81.        
  82.    }
  83. ?>


tabela1
id image0 image1 image2 image3

tabela2
.. .. . .. . tabela1_id ... ..

Logika jest taka ze odbieram tablice file przerabiam ja, sprawdzam w innej klasie pliki czy sa poprawne i teraz mam problem nie wiem czy jest to sluszne rozumowanie. Wrzucam najpierw pliki do bazy nastepnie pobieram ostatnie ID i wrzucam do drugiej tabeli (tabela1_id). Pliki rowniez nazywam: ostatnie ID - nazwa pliku.

Chodzi o to ze zapytanie do bazy idzie w petli i nie moge pobrac ostaniego ID dla drugiej tabeli. Pliki laduja sie z poprawna nazwa. Moze jakies inne pomysly?