Jump to content

Recommended Posts

on my site www.budstreasureauctions.com there is a featured auctions box that users will pay to get there picture on the homepage.  currently the box limit is 6.  If you increase the limit then it will display the images in a row side by side continuously.  I need it to display 6 per row then start a new row of 6, so on,  so on.

 


here is the current code:

<? 	$feature_sql="select * from featuredproducts f,auction_details p where p.status='Active' and selling_method!='ads' and selling_method!='want_it_now' and home_feature='yes' and picture1!='' and p.bid_starting_date <= NOW() and f.productid=p.productid  order by rand() limit 6";
$feature_res=mysql_query($feature_sql);
$tot_count=mysql_num_rows($feature_res);
if($tot_count!=0)
{
 ?>
<table border="0" align="center" cellpadding="0" cellspacing="0" width=574>
<tr>
<td colspan=4 height="30" valign="middle">
<table width="574" cellpadding="0" cellspacing="0" >
<tr>
<tr class="tdhead"><td width="1%" height="30" valign="top"><img src=templates/<?=$tfold?>/img_files/h_left.gif></td>
<td width="98%" height="30" valign="middle"> <B>Featured Auctions</b>  <a href="rssfeatured.php" target="_blank"><img src=templates/<? echo "$tfold" ?>/img_files/xml.gif border="0"></a></td>
<td width="1%" height="30" valign="top"><img src=templates/<?=$tfold?>/img_files/h_right.gif></td></tr>
</tr>
</table>
</tr></table>
<table border="0" align="center" cellpadding="0" cellspacing="0" width=574 class="ft_right">
<?
}
?>
  	<?
    $count=0;
while($feature_row=mysql_fetch_array($feature_res))
	{ 
    $expire_date = $feature_row['expire_date']; 
    require 'ends.php';
$string_1=$feature_row[detailed_descrip];
$count=$count+1; 
	?>
<td valign=top>
<table cellpadding=5 cellspacing=2>
<td >
<? if(empty($feature_row['picture1']))
{ ?>
<table height="49" border="0" cellpadding=0 cellspacing=0>
	<tr>
	<td height="12" background="templates/<? echo "$tfold" ?>/img_files/window_01.gif" ></td>
	</tr>
	<tr>
	<td background="templates/<? echo "$tfold" ?>/img_files/window_03.gif" >

	<table border="0" cellpadding="0" cellspacing="0" width=77>
	<tr valign="top">
	<td align="center">
<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
<? echo $featured_row['producttitle']; ?>
 <img src="templates/<? echo "$tfold" ?>/img_files/noimage2.gif" width=<?= $w; ?> height=<?=$h?> border=0>
</a>
</td>
	</tr>
	</table>
	</td>
	</tr><tr>
<? 
	$bid_sql="select * from site_bids where productid=".$feature_row['productid'];
    $bid_res=mysql_query($bid_sql);
$bid_tot_row=mysql_num_rows($bid_res);
if($bid_tot_row!=0)
{
$bid_row=mysql_fetch_array($bid_res);
$curprice=$bid_row['bidding_amount'];
}
else
{
$curprice=$feature_row['min_bid_amount'];
}
if($feature_row['selling_method']=="fix")
{
$curprice=$feature_row['quick_buy_price'];
} 
?>
<td valign=top align="center"><br><a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
<? echo $feature_row['producttitle'];?></a><br> <? echo "Price: ".$feature_row['currency']." ".$curprice; ?>
<br>
	<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>" style="text-decoration:none;">

<?= $string_difference; ?>
</a>
</td>
</tr>
	</table>

<?
}
else
{

               $img=$feature_row['picture1'];
			   list($width, $height, $type, $attr) = getimagesize("uploads/$img");
			   $h=$height;
			   $w=$width;
			   if($h>60)	
			   {
			   $nh=60;
			   $nw=($w/$h)*$nh;
			   $h=$nh;
			   $w=$nw;
			   }
			  if($w>60)
			  {
			  $nw=60;
			  $nh=($h/$w)*$nw;
			  $h=$nh;
			  $w=$nw;
			  }

?>
<table height="49" border="0" cellpadding=0 cellspacing=0 align=center>
	<tr>
	<td height="12" ></td>
	</tr>
	<tr>
	<td align=center>
<center>
	<table border="1" cellpadding="0" cellspacing="0" width=65 height=65 bordercolor="#000000">
	<tr valign="top">
	<td align="center" bgcolor="#ffffff">
<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
<? echo $featured_row['producttitle']; ?>
 <img src="uploads/<? echo $feature_row['picture1']; ?>" width=<?= $w; ?> height=<?=$h?> border=0>
</a>
</td>
	</tr>
	</table></center>
	</td>
	</tr>
<tr>
<? 
	$bid_sql="select * from site_bids where productid=".$feature_row['productid'];
    $bid_res=mysql_query($bid_sql);
$bid_tot_row=mysql_num_rows($bid_res);
if($bid_tot_row!=0)
{
$bid_row=mysql_fetch_array($bid_res);
$curprice=$bid_row['bidding_amount'];
}
else
{
$curprice=$feature_row['min_bid_amount'];
}
if($feature_row['selling_method']=="fix")
{
$curprice=$feature_row['quick_buy_price'];
} 
?>
<td valign=top align="center"><br><a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
<? echo $feature_row['producttitle'];?></a><br> <? echo "Price: ".$feature_row['currency']." ".$curprice; ?>
<br>
	<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>" style="text-decoration:none;">

<?= $string_difference; ?>
</a>
</td></tr>

	</table>
<? 
}
?>
</td>
</tr>
</table>
</td>	<?
}
?>
<?	if($tot_count!=0)
{ ?>
</tr>
</table>

<?
}
    ?>

 

Link to comment
https://forums.phpfreaks.com/topic/187963-start-new-row-of-pictures/
Share on other sites

Here's a sample from one of my scripts:

$incr = 3;

while ($r = mysql_fetch_array($result)) {

   $incr = ($incr == 3) ? 1 : $incr + 1;

   if($incr == 1) echo '<tr align="center">';

   $db_id = $r['id'];

$db_name = $r['name'];

echo '<td valign="top" align="left"><center><div class="gamecontain"><a href="index.php?id=games&game_id='.$db_id.'"><img src="games/images/'.stripslashes($db_name).'.jpg" border="0" /></a><br><a href="index.php?id=games&game_id='.$db_id.'" class="boldlink">'.$db_name.'</a></div></center></td>';

   if($incr == 3) echo "</tr>";

}

if($incr == 1) echo '<td></td><td></td></tr>';

if($incr == 2) echo '<td></td></tr>';

alternatively - instead of using tables us a <ul> put each picture in an <li> and float the li left.  that way once they hit the end of a line the next picture will move onto the next.... don't have to do any math to work out when to start/end a row and its easier to manage clientside with css.

<?php
$incr = 3;

while ($r = mysql_fetch_array($result)) {

   $incr = ($incr == 3) ? 1 : $incr + 1;

   if($incr == 1) echo '<tr align="center">';

   $db_id = $r['id'];

$db_name = $r['name'];

echo '<td valign="top" align="left"><center><div class="gamecontain"><a href="index.php?id=games&game_id='.$db_id.'"><img src="games/images/'.stripslashes($db_name).'.jpg" border="0" /></a><br><a href="index.php?id=games&game_id='.$db_id.'" class="boldlink">'.$db_name.'</a></div></center></td>';

   if($incr == 3) echo "</tr>";

}

if($incr == 1) echo '<td></td><td></td></tr>';

if($incr == 2) echo '<td></td></tr>';
?>

 

vs.

 

<?php

while ($r = mysql_fetch_array($result)) {

echo '<li><a href="index.php?id=games&game_id='.$r['id'].'"><img src="games/images/'.stripslashes($r['name']).'.jpg" border="0" /></a><br><a href="index.php?id=games&game_id='.$r['id'].'" class="boldlink">'.$r['name'].'</a></li>';

}

?>

 

I know which one I'd rather have to maintain...

yep i am lost on it.. I keep getting a blank screen obviously i just dont understand this.  I just cant figure it out

 

avl8386:  here is how (like) you would use tail's script in your own - as you can see, not that much different from what you are already doing.

Toon:  sorry - meant no offense, both solutions are good solutions.  tail's just requires less of a code change in this case.  ty

 


<?    $feature_sql="select * from featuredproducts f,auction_details p where p.status='Active' and selling_method!='ads' and selling_method!='want_it_now' and home_feature='yes' and picture1!='' and p.bid_starting_date <= NOW() and f.productid=p.productid  order by rand()";
   $feature_res=mysql_query($feature_sql);
   $tot_count=mysql_num_rows($feature_res);
   if($tot_count!=0)
   {
   ?>
   	<table border="0" align="center" cellpadding="0" cellspacing="0" width=574>
   		<tr>
   		<td colspan=4 height="30" valign="middle">
   			<table width="574" cellpadding="0" cellspacing="0" >
   				<tr class="tdhead"><td width="1%" height="30" valign="top"><img src=templates/<?=$tfold?>/img_files/h_left.gif></td>
			<td width="98%" height="30" valign="middle"> <B>Featured Auctions</b>  <a href="rssfeatured.php"  target="_blank"><img src=templates/<? echo "$tfold" ?>/img_files/xml.gif border="0"></a></td>
			<td width="1%" height="30" valign="top"><img src=templates/<?=$tfold?>/img_files/h_right.gif></td></tr>
			</tr>
		</table>
	</td>
	</tr>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0" width=574 class="ft_right">
        
   <?
   }
   ?>
   <?
   $count=0;
   
   $incr = 6;
   while($feature_row=mysql_fetch_array($feature_res))
   {
      $incr = ($incr == 6) ? 1 : $incr+1;

      if ($incr == 1) echo '<tr align="center">';

      $expire_date = $feature_row['expire_date'];
      require 'ends.php';
      $string_1=$feature_row[detailed_descrip];
      $count=$count+1;
   ?>
   	<td valign=top>
   		<table cellpadding=5 cellspacing=2>
	<tr>
   		<td >
   <? if(empty($feature_row['picture1']))
      { ?>
   			<table height="49" border="0" cellpadding=0 cellspacing=0>
      				<tr>
      				<td height="12" background="templates/<? echo "$tfold" ?>/img_files/window_01.gif" ></td>
      				</tr>
      				<tr>
      				<td background="templates/<? echo "$tfold" ?>/img_files/window_03.gif" >
      
      					<table border="0" cellpadding="0" cellspacing="0" width=77>
      						<tr valign="top">
      						<td align="center">
   						<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
   						<? echo $featured_row['producttitle']; ?>
    						<img src="templates/<? echo "$tfold" ?>/img_files/noimage2.gif" width=<?= $w; ?> height=<?=$h?> border=0>
   						</a>
   						</td>
      						</tr>
      					</table>
      				</td>
      				</tr>
			<tr>
   <?
         $bid_sql="select * from site_bids where productid=".$feature_row['productid'];
         $bid_res=mysql_query($bid_sql);
         $bid_tot_row=mysql_num_rows($bid_res);
         if($bid_tot_row!=0)
         {
            $bid_row=mysql_fetch_array($bid_res);
            $curprice=$bid_row['bidding_amount'];
         }
         else
         {
            $curprice=$feature_row['min_bid_amount'];
         }
         if($feature_row['selling_method']=="fix")
         {
            $curprice=$feature_row['quick_buy_price'];
         }
   ?>
   				<td valign=top align="center"><br><a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
   <? echo $feature_row['producttitle'];?></a><br> <? echo "Price: ".$feature_row['currency']." ".$curprice; ?>
   				<br>
      				<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>" style="text-decoration:none;">

    <?= $string_difference; ?>
   				</a>
			</td>
			</tr>
      			</table>
      
   <?
      } //if empty feature row
      else
      {
   
                  $img=$feature_row['picture1'];
               list($width, $height, $type, $attr) = getimagesize("uploads/$img");
               $h=$height;
               $w=$width;
               if($h>60)   
               {
               $nh=60;
               $nw=($w/$h)*$nh;
               $h=$nh;
               $w=$nw;
               }
              if($w>60)
              {
              $nw=60;
              $nh=($h/$w)*$nw;
              $h=$nh;
              $w=$nw;
              }
   
   ?>
   			<table height="49" border="0" cellpadding=0 cellspacing=0 align=center>
     				<tr>
      				<td height="12" ></td>
      				</tr>
      				<tr>
      				<td align=center>
			<center>
      				<table border="1" cellpadding="0" cellspacing="0" width=65 height=65 bordercolor="#000000">
      					<tr valign="top">
      					<td align="center" bgcolor="#ffffff">
   					<a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
   <? echo $featured_row['producttitle']; ?>
    					<img src="uploads/<? echo $feature_row['picture1']; ?>" width=<?= $w; ?> height=<?=$h?> border=0>
   					</a>
   					</td>
      					</tr>
      				</table>
			</center>
      				</td>
      				</tr>
			<tr>
   <?
         $bid_sql="select * from site_bids where productid=".$feature_row['productid'];
         $bid_res=mysql_query($bid_sql);
         $bid_tot_row=mysql_num_rows($bid_res);
         if($bid_tot_row!=0)
         {
            $bid_row=mysql_fetch_array($bid_res);
            $curprice=$bid_row['bidding_amount'];
         }
         else
         {
            $curprice=$feature_row['min_bid_amount'];
         }
         if($feature_row['selling_method']=="fix")
         {
            $curprice=$feature_row['quick_buy_price'];
         }
   ?>
   				<td valign=top align="center"><br><a href="itechd.php?productid=<? echo $feature_row['productid']; ?>">
   <? echo $feature_row['producttitle'];?></a><br> <? echo "Price: ".$feature_row['currency']." ".$curprice; ?>
   					<br>
   					   <a href="itechd.php?productid=<? echo $feature_row['productid']; ?>" style="text-decoration:none;">

<?= $string_difference; ?>
   					</a>
			</td>
			</tr>

      			</table>
   <?
      }
   ?>
   		</td>
	</tr>
   		</table>
   	</td>   
   <?
      if ($incr == 6) echo "</tr>";
   } //end while loop
   if ($incr < 6) {
      while ($incr <= 6) {
         echo "<td></td>";
         $incr++;
      }
      echo "</tr>";
   }
   ?>
   <?   if($tot_count!=0)
        { ?>
   	
</table>
   
   <?
        }
    ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.