Article View: pl.comp.objects
Article #14629Re: wydajnosc GenericObject
From: Marek Wywial
Date: Fri, 21 Apr 2006 16:06
Date: Fri, 21 Apr 2006 16:06
59 lines
2800 bytes
2800 bytes
Chyba popelnilem skrót myslowy i nie wytlumaczylem wszystkiego :)
teraz mam tak:
// lista ID produktów, które maja zostac stworzone i wyswietlone
$arProdId = array( 1, 2, 3, 4, 5, 6, 7, 8) // pobrane selectem z bazy
//i aby otrzymac wszystkie te produky wykonuje:
$kolekcjaProduktow = Collection::createCollection($arProdId);
kolekcja wykonuje:
class Collection {
...
// po otrzymaniu tablicy z ID'ami
function createCollection($arProdId) {
// iteruje ta tablice
foreach($arProdId as $intProdId) {
// i dla kazdego ID tworzy odpowiedni obiekt produkt
$this->_object[$id] = new ProductObject($id);
}
return $this->_objects;
}
...
}
[1] Konstruktor ProductObject wykonuje:
..
__construct($id) {
$this->_fields = $db->GetAll("SELECT * FROM products WHERE
id='$id'");
}
i wlasnie stad bierze sie seria zapytan do bazy
Pomyslem moze byc nadpisanie konstruktora w ProductObject aby jako
dane wejsciowe mógl pobrac dane pobrane selectem zbiorczym
wczesniej i zamiast selecta swojego uzyc te dane ? ale czy to jest
madre ?
czyli
$arProdukty = $db->getAll("SELECT * from produkty where id in(1,2,3,4);
foreach($arProdukty as $arProdukt) {
$arrayProdukty[] = new ProduktObject($arProdukt);
}
a ProductObject:
__construct($data) {
if(is_Array($data)) {
$this->_fields = $data;
} else {
$this->_fields = $db->getAll("SELECT * from produkty WHERE
id='$data'");
}
a moze juz bredze po 5 dniach pracy :)
pozdrawiam,
Technical Details
Message-ID:
<1145635619.455818.31630@v46g2000cwv.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.task.gda.pl!fu-berlin.de!postnews.google.com!v46g2000cwv.googlegroups.com!not-for-mailReferences:
<1145621432.199758.292090@j33g2000cwa.googlegroups.com> <e2ajvu$1e4$1@tkdami.pl> <1145626731.132393.85910@i39g2000cwa.googlegroups.com> <e2aqno$a99$1@tkdami.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!news.task.gda.pl!fu-berlin.de!postnews.google.com!v46g2000cwv.googlegroups.com!not-for-mail From: "Marek Wywial" <onjinx@gmail.com> Newsgroups: pl.comp.objects Subject: Re: wydajnosc GenericObject Date: 21 Apr 2006 09:06:59 -0700 Organization: http://groups.google.com Lines: 60 Message-ID: <1145635619.455818.31630@v46g2000cwv.googlegroups.com> References: <1145621432.199758.292090@j33g2000cwa.googlegroups.com> <e2ajvu$1e4$1@tkdami.pl> <1145626731.132393.85910@i39g2000cwa.googlegroups.com> <e2aqno$a99$1@tkdami.pl> NNTP-Posting-Host: 80.53.98.66 Mime-Version: 1.0 X-Trace: posting.google.com 1145635624 30795 127.0.0.1 (21 Apr 2006 16:07:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 21 Apr 2006 16:07:04 +0000 (UTC) In-Reply-To: <e2aqno$a99$1@tkdami.pl> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.8.0.2) Gecko/20060419 Firefox/1.5.0.2,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 inktec.pl:8080 (squid/2.5.STABLE5) Complaints-To: groups-abuse@google.com Injection-Info: v46g2000cwv.googlegroups.com; posting-host=80.53.98.66; posting-account=yYBjiw0AAACo2m33lSXuI5tzd2bcLd_U Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit