Jump to content
php.lv forumi

Attēlu izvilkšana no db pa 5 ierakstiem


Cibiņš

Recommended Posts

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 by Cibiņš
Link to comment
Share on other sites

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>':'';
};

Link to comment
Share on other sites

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 :))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...