Cibiņš Posted November 23, 2010 Report Share Posted November 23, 2010 (edited) Kā īsti var panākt lai šāds <? $resulta = mysql_query("SELECT * FROM pg_pages ORDER BY position"); if (!mysql_num_rows($resulta)) { ?> <div>Nav pievienotu attēlu!</div> <? } else { while($r2=mysql_fetch_array($resulta)) { $imgname=$r2["img_thumb"]; ?> <div><img src="path1/path2/<? echo $imgname; ?>.jpg"></div> <? } } ?> no visiem ierakstiem datubāzē izvelk attēlus pa 5 iekš div? Tipa lai pašā lapā veidotos šāds <div> <img src="path1/path2/3323896446_3b87a8bf75_t.jpg"> <img src="path1/path2/3323897466_e61624f6de_t.jpg"> <img src="path1/path2/3323058611_d35c894fab_t.jpg"> <img src="path1/path2/3323893254_3183671257_t.jpg"> <img src="path1/path2/3323893148_8318838fbd_t.jpg"> </div> <div> <img src="path1/path2/3323896446_3b87a8bf75_t.jpg"> <img src="path1/path2/3323897466_e61624f6de_t.jpg"> <img src="path1/path2/3323058611_d35c894fab_t.jpg"> <img src="path1/path2/3323893254_3183671257_t.jpg"> <img src="path1/path2/3323893148_8318838fbd_t.jpg"> </div> kur iekš div elementa ir 5 ieraksti nevis kautkāds šāds <div><img src="path1/path2/3323896446_3b87a8bf75_t.jpg"></div> <div><img src="path1/path2/3323897466_e61624f6de_t.jpg"></div> <div><img src="path1/path2/3323058611_d35c894fab_t.jpg"></div> <div><img src="path1/path2/3323893254_3183671257_t.jpg"></div> <div><img src="path1/path2/3323893148_8318838fbd_t.jpg"></div> Edited November 23, 2010 by Cibiņš Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 23, 2010 Report Share Posted November 23, 2010 Kustinām smadzeni.... =( <div> <?php while() { } ?> </div> Quote Link to comment Share on other sites More sharing options...
Val Posted November 23, 2010 Report Share Posted November 23, 2010 koda gabals else { $i = 0; while($r2=mysql_fetch_array($resulta)) { $imgname=$r2['img_thumb']; echo ($i%5==0)?'<div>':''; ?><img src="path1/path2/<? echo $imgname; ?>.jpg"><?php echo ($i%5==4)?'</div>':''; $i++; }; echo (mysql_num_rows($resulta)%5!==0)?'</div>':''; }; Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted November 23, 2010 Author Report Share Posted November 23, 2010 koda gabals else { $i = 0; while($r2=mysql_fetch_array($resulta)) { $imgname=$r2['img_thumb']; echo ($i%5==0)?'<div>':''; ?><img src="path1/path2/<? echo $imgname; ?>.jpg"><?php echo ($i%5==4)?'</div>':''; $i++; }; echo (mysql_num_rows($resulta)%5!==0)?'</div>':''; }; Ideāli, paldies vecīt, cepums Tev :)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.