jupper Posted August 11, 2005 Report Share Posted August 11, 2005 ir tabula ar trīs laukiem: id, picturename, picturewidth vajag atlasīt tik daudz ierakstus, kuru lauku vērtība "picturewidth" summa nepārsniedz kādu noteiktu skaitli, piemēram, 1000, respektīvi, kad ir sasniegts šis mainīgais, tad selects tiek pārtraukts. Kā to izdarīt ar vienu selectu?? Link to comment Share on other sites More sharing options...
Grey_Wolf Posted August 11, 2005 Report Share Posted August 11, 2005 vairaak info! kas tev tur glabaajas (picturewidth) ? dazaadi skaitlji ? tos skaitiit kopaa ? un tad reekjinaat ? bet ja vaijag atlasiit kaadu dalju tad ir LIMIT no, liidz buus ieraksti no liidz teiksim LIMIT 30 paraadis pirmos 30 ierakstus (atbilstoshos pieprasiijumam) LIMIT 30, 100 no 30 liidz 100 utt... Link to comment Share on other sites More sharing options...
jupper Posted August 11, 2005 Author Report Share Posted August 11, 2005 "picturewidth" glabaajas attēla platums pikseļos. Man vajag atlasīt tik daudz ierakstus no mysql datu bāzes, lai kopējā visu bilžu platuma summa nepārsniegtu, piemēram, 1000. Ja kopējais platums būs lielāks par 1000, tad tiks sabojāts lapas dizains. Ar LIMIT neder, jo bilžu platumi ir dažādi. Link to comment Share on other sites More sharing options...
Kristabs Posted August 11, 2005 Report Share Posted August 11, 2005 $w = 0; $sql = "select picture, width from taabuljaars"; $rez = mysql_query($sql); while($row = mysql_fetch_array($rez)){ if($w < 1000){ echo "<img... src=\"{$row['picture']}\">";} $w = $w + $row['width']; } Link to comment Share on other sites More sharing options...
bubu Posted August 11, 2005 Report Share Posted August 11, 2005 (edited) mysql_query() vietā Kristaba piemērā lieto mysql_unbuffered_query() un būs ok (tikai mysql_close() neaizmirsti). Edited August 11, 2005 by bubu Link to comment Share on other sites More sharing options...
v3rb0 Posted August 11, 2005 Report Share Posted August 11, 2005 ja mysql5 tad ar storeeto proceduru vareetu - atver kursoru, ej vinjam cauri, summee platumus kaadaa proceduras mainiigaa un salasi rezultatu kameer nav 1000 px platums. Link to comment Share on other sites More sharing options...
jupper Posted August 11, 2005 Author Report Share Posted August 11, 2005 to Kristabs bet ja datu bāzē vaīrāki tūkstoši bildes!!!! Ok, izdrukās ta visu pareizi, bet cikls while tad tik un tā izies cauri visiem ierakstiem! Link to comment Share on other sites More sharing options...
v3rb0 Posted August 11, 2005 Report Share Posted August 11, 2005 pieliec limit.. ja 1000px max, tad iespeejams vairaak par 10 (20, nu kaut vai100) bildeem nekad tev nevajadzees dabuut. Link to comment Share on other sites More sharing options...
bubu Posted August 11, 2005 Report Share Posted August 11, 2005 Pieliec papildus ifu tak: if ($w>=1000) break; Link to comment Share on other sites More sharing options...
Kristabs Posted August 11, 2005 Report Share Posted August 11, 2005 $w = 0; $sql = "select picture, width from taabuljaars"; $rez = mysql_unbuffered_query($sql); while($row = mysql_fetch_array($rez)){ if($w < 1000){ echo "<img... src=\"{$row['picture']}\">"; $w = $w + $row['width'];} else{ endwhile; } } mysql_close(); Link to comment Share on other sites More sharing options...
jupper Posted August 11, 2005 Author Report Share Posted August 11, 2005 paldies visiem:) Link to comment Share on other sites More sharing options...
bubu Posted August 11, 2005 Report Share Posted August 11, 2005 ui, es saputrojos :) mysql_close() vietā ieliec mysql_free_result($rez) lai atbrīvojas tas viss izselektētais blāķis. Link to comment Share on other sites More sharing options...
Analgiins Posted August 11, 2005 Report Share Posted August 11, 2005 (edited) hm, kaut ko varbuut nesapratu, bet vai shitas neder: SELECT * FROM tabula WHERE picturewidth < 1000; Edited August 11, 2005 by Analgiins Link to comment Share on other sites More sharing options...
bubu Posted August 11, 2005 Report Share Posted August 11, 2005 Analgiins: nesaprati. Viņam vajag dabūt no tabulas rindiņas, kurās saskaitot visas kolonnu 'pictureWidth' vērtības summa nepārsniedz 1000. Nevis katrā rindiņā, bet visa kopējā summa! Link to comment Share on other sites More sharing options...
Analgiins Posted August 11, 2005 Report Share Posted August 11, 2005 nu skaidrs. Taa aatri paarlasiju, iisti neiedziljinoties :) Link to comment Share on other sites More sharing options...
Recommended Posts