Jump to content

</br> After 3


justlukeyou

Recommended Posts

Hi,

 

I am trying to display products which return after 3.  So there are 5 rows of 3.  I have tried adding a loop but I just cant get it to work.  Can anyone advise me on how I can insert a </br> after every 3 items.

 

 

<?php
$query = "SELECT * FROM productfeed LIMIT 0, 15";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];


$i = $i;

for($i=0; $i<=3; $i=$i+1)


echo 
"<div class='productpagemenu'>
<div class='productpagedescription'>
<center>
<a href='$link' target='_blank' >$description</a>
</center> 
</div>
<div class='productpageimage'>
<center>
<a href='$link' target='_blank'><img src='$image' width=\"95%\"/></a>
</center> 
</div>
<div class='productpageprice'>
<center>
<center>&#163; $price</center>
</center> 
</div>
<div class='productpagepricebutton'>
<center>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</center> 
$i </br>
</div>
</div>";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/230024-after-3/
Share on other sites

Hi justlukeyou,

If I understand you correctly, this is what you want:

 

<?php
$query = "SELECT * FROM productfeed LIMIT 0, 15";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');

$i = 1;

while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];

echo 
"<div class='productpagemenu'>
    <div class='productpagedescription'>
        <center>
        <a href='$link' target='_blank' >$description</a>
        </center> 
    </div>
    <div class='productpageimage'>
        <center>
        <a href='$link' target='_blank'><img src='$image' width=\"95%\"/></a>
        </center> 
    </div>
    <div class='productpageprice'>
        <center>
        <center>&#38;#163; $price</center>
        </center> 
    </div>
    <div class='productpagepricebutton'>
        <center>
        <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
        </center> 
    </div>
</div>";

if ($i % 3 == 0) {
    echo "<br />";
}
$i++;
}
?>

 

cheers,

Fergal

Link to comment
https://forums.phpfreaks.com/topic/230024-after-3/#findComment-1184709
Share on other sites

try this. increment a variable then check the remainder    e.g.    $a=3;  $a%3==0;    echo ($a%3==0)?"<br>":"";

$a=0; 
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];
echo (($a%3)==0)?"<br>":""; 
echo 
"<div class='productpagemenu'>
<div class='productpagedescription'>
<center>
<a href='$link' target='_blank' >$description</a>
</center> 
</div>
<div class='productpageimage'>
<center>
<a href='$link' target='_blank'><img src='$image' width=\"95%\"/></a>
</center> 
</div>
<div class='productpageprice'>
<center>
<center>&#38;#163; $price</center>
</center> 
</div>
<div class='productpagepricebutton'>
<center>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</center> 
$i </br>
</div>
</div>";
$a++; 
}

Link to comment
https://forums.phpfreaks.com/topic/230024-after-3/#findComment-1184714
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.