I got a class, wich saves pictures and assigns a gallery to the picture and a function in the picture-class which writes a new sort index into the same database table.
PHP Code:
class picture {
function save() {
getDB()->sendQuery(insert into pictures...);
$gallery = new gallery();
$gallery->update();
}
function sort() {
getDB()->sendQuery(Select gallery from pictures ...);
getDB()->sendQuery(Update pictures set sortindex ...);
}
function activate() {
$this->save();
$this->sort();
}
}
class gallery {
function update() {
getDB()->sendQuery(update pictures set gallery = ...);
}
}
if i do this for one photo, it works without any problems...BUT...if i run this for more photos in a foreach{} it stops sometimes after the first, sometimes after the second picture and tells me, that the query
SELECT gallery from pictures...
in the sort-function is not valid, as there is no valid gallery.
it seems, that the table is not updated yet.
if i add a small delay like
PHP Code:
function activate() {
$this->save();
sleep(2);
$this->sort();
}
it works fine for all pictures in my foreach{}. It seems, that PHP is not waiting till the save() is finished prior it calls activate().
Is it a problem, that i use different classes for it? are they working independent? Is there a possibility to say PHP it should wait till the save() of the picture class is finished?
Bookmarks