Hi can someone tell me what I have to change i my code to let the output be in 2 collumns instead of one.

If its possible it could be nice to have the top 10 list like this:
1 2
3 4
5 6
7 8
9 10

Here is my code, Thanks:

echo "\n<h2>Top 10 Coupons</h2>";
db_connect ($cfg["db_server"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_database"]);
$sql_sms = ("SELECT FROM sms");
$result_sms = db_query ($sql_sms);
$row_sms = mysql_fetch_array($result_sms);
$sms_enabled = $row_sms['enabled'];
$now = time();
$sql = "SELECT
,c.expire as exdate, b.business as business FROM coupons c,businesses b,users u WHERE c.business=b.business and u.user=b.user and u.billing=1 and c.approved=1 order by c.prints DESC";
$result = db_query ($sql);
//echo "$sql";
echo "\n\t<table width='100%' cellpadding='4' class='coupon' style='table-layout:fixed;'>\n";
$i=3;
$num = 0;
while (($row=mysql_fetch_object($result)) && ($num < 10)) {
if (isDateExpired($row->exdate)) {
continue;
}
if ($i==3) {$i=2;}
if ($i==2) {echo "\n<tr>";$i=0;}
echo "\n<!-- begin coupon $num -->";
echo "\n\t<Tr>";
$id = $row->coupon;
$ids[][0] = $id;
$j=count($ids) - 1;
$ids[$j][1] = $row->views;
unset ($coupon);
$busname = $row->name;
$busId = $row->business;
$coupon[] = $row->name;
$coupon[] = $row->title;
$coupon[] = $row->price;
$coupon[] = $row->subtitle;
$coupon[] = $row->terms;
$coupon[] = $row->exdate;
$coupon[] = $row->views;
$coupon[] = $row->prints;
$coupon[] = "barcodes/". $row->barcode;
$coupon[] = $id;
$coupon[] = $row->business;
if ($row->couponlogo == 'yes') {
$coupon[] = 'coupon'.$id.'.jpg';
}
echo "\n\t\t<td width='100%' align='center' valign='top'>";
print_coupon ($coupon,2,$cfg);
$i++;

		echo "\n\t\t</td>";
		echo "\n\t</tr>";
		echo "\n<!-- end coupon $num -->";
	$num++;

	}
	mysql_close();
	if ($i==1) {echo"<td width='50%'>";}
	echo "</table>";

	//increment view information for each coupon
	for ($i=0;$i<count($ids);$i++) {
		db_connect ($cfg["db_server"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_database"]);
		$views = ($ids[$i][1]) + 1; $coupon = $ids[$i][0];
		$sql = "update coupons set views='$views' where coupon='$coupon'";
		$result = db_query ($sql);
		mysql_close();
	}
    echo "\n\t<table width='100%' cellpadding='4' class='coupon' style='table-layout:fixed;'>\n";
    $num = 0;
    $count = 0;
    while ( $num < 10 ) {
      if(($count%2)==0)
        echo '<tr>';
      echo "\n\t\t<td width='100%' align='center' valign='top'>";
      echo "\n\t\t</td>";
      if( (($count%2)!=0) )
        echo '</tr>';
      $num++;
      $count++;
    }
    echo "</table>";
      PradeepKr;10962234 wrote:
      echo "\n\t<table width='100%' cellpadding='4' class='coupon' style='table-layout:fixed;'>\n";
      $num = 0;
      $count = 0;
      while ( $num < 10 ) {
        if(($count%2)==0)
          echo '<tr>';
        echo "\n\t\t<td width='100%' align='center' valign='top'>";
        echo "\n\t\t</td>";
        if( (($count%2)!=0) )
          echo '</tr>';
        $num++;
        $count++;
      }
      echo "</table>";

      Thank for your quick reply. Im a newbee in PHP. Which part of my old code do I have to swap with yours?

        Replace all you posted with this

        <?php
        echo "\n<h2>Top 10 Coupons</h2>";
        db_connect ($cfg["db_server"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_database"]);
        $sql_sms = ("SELECT * FROM sms");
        $result_sms = db_query ($sql_sms);
        $row_sms = mysql_fetch_array($result_sms);
        $sms_enabled = $row_sms['enabled'];
        $now = time();
        $sql = "SELECT *,c.expire as exdate, b.business as business FROM coupons c,businesses b,users u WHERE c.business=b.business and u.user=b.user and u.billing=1 and c.approved=1 order by c.prints DESC";
        $result = db_query ($sql);
        //echo "$sql";
        echo "\n\t<table width='100%' cellpadding='4' class='coupon' style='table-layout:fixed;'>\n";
        $i=3;
        $num = 0;    
        $count = 0; while (($row=mysql_fetch_object($result)) && ($num < 10)) { if (isDateExpired($row->exdate)) { continue; } echo "\n<!-- begin coupon $num -->"; if(($count%2)==0) echo '<tr>'; $id = $row->coupon; $ids[][0] = $id; $j=count($ids) - 1; $ids[$j][1] = $row->views; unset ($coupon); $busname = $row->name; $busId = $row->business; $coupon[] = $row->name; $coupon[] = $row->title; $coupon[] = $row->price; $coupon[] = $row->subtitle; $coupon[] = $row->terms; $coupon[] = $row->exdate; $coupon[] = $row->views; $coupon[] = $row->prints; $coupon[] = "barcodes/". $row->barcode; $coupon[] = $id; $coupon[] = $row->business; if ($row->couponlogo == 'yes') { $coupon[] = 'coupon'.$id.'.jpg'; } echo "\n\t\t<td width='100%' align='center' valign='top'>"; print_coupon ($coupon,2,$cfg); $i++; echo "\n\t\t</td>"; if( (($count%2)!=0) ) echo '</tr>'; $count++; echo "\n<!-- end coupon $num -->"; $num++; } mysql_close(); echo "</table>"; //increment view information for each coupon for ($i=0;$i<count($ids);$i++) { db_connect ($cfg["db_server"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_database"]); $views = ($ids[$i][1]) + 1; $coupon = $ids[$i][0]; $sql = "update coupons set views='$views' where coupon='$coupon'"; $result = db_query ($sql); mysql_close(); } ?>

          Hi Pradeepkr your are the best. That works perfectly thanks :-)

            Write a Reply...