PHP Code that reads left to right

220 Views Asked by At

I've used a version of this code before and it would spit out my content left to right like it should. I can't get it to read this way for a new project and was looking for some help. It reads as:

A A A
B B B
C C C

Instead of

A B C
D E F

Here is a link to what it looks like and the code, any help would be greatly appreciated, thanks.

http://www.amphenol-industrial.com/test

<table style="width: 100%;" sizcache="14" sizset="0" border="0" cellpadding="0" cellspacing="0">
<tbody sizcache='14' sizset='0'>
<?


// Make a MySQL Connection
mysql_connect("localhost", "amphenol_web", "ampheweb") or die(mysql_error());
mysql_select_db("amphenol_conn") or die(mysql_error());

// Retrieve all the data from the "distributors" table
$query = "SELECT * FROM products WHERE page = '1' ORDER BY name";


$result = mysql_query($query) or die(mysql_error());




$cols = 6;     // Here we define the number of columns




echo "<table>"; // The container table with $cols columns
    do{
        echo "<tr>";
        for($i=1;$i<=$cols;$i++){   // All the rows will have $cols columns even if
                                    // the records are less than $cols
            $row=mysql_fetch_array($result);


?>
<?

$image = $row['image'];
$name = $row['name'];
$description = $row['description'];
$link = $row['link'];
$page = $row['page'];

if ($image == ""){echo "<td>&nbsp;</td>";}
    else {echo

        "<tr valign='top'>
<td><a href='$link'"?> onclick="_gaq.push(['_trackEvent', 'Clicks', 'Connectors', '<?php echo "$name"?>']);"><? echo "<img style='border: #015d90 1px solid;' alt='$name' src='/$image' height='74' width='120' /></a></td>             
<td width='2'>&nbsp;</td>
<td><span style='font-family: andale mono,times; font-size: 8pt;'><b>$name:</b> $description</span></td>
<td><span style='font-family: andale mono,times; font-size: 8pt;'><b>&nbsp;</b></span></td>

<td><span style='font-size: 8pt;'><a href='$link'"?> onclick="_gaq.push(['_trackEvent', 'Clicks', 'Connectors', '<?php echo "$name"?>']);"><? echo "<img style='border: #015d90 1px solid;' alt='AC Threaded' src='$image' height='74' width='120' /></a></span></td>
<td width='2'>&nbsp;</td>
<td><span style='font-family: andale mono,times; font-size: 8pt;'><b>$name:</b> $description</span></td>
<td><span style='font-family: andale mono,times; font-size: 8pt;'><b>&nbsp;</b></span></td>

<td><a href='$link'"?> onclick="_gaq.push(['_trackEvent', 'Clicks', 'Connectors', '<?php echo "$name"?>']);"><? echo "<img style='border: #015d90 1px solid;' alt='$name' src='$image' height='74' width='120' /></a></td>
<td width='2'>&nbsp;</td>
<td><span style='font-family: andale mono,times; font-size: 8pt;'><b>$name:</b> $description</span></td>
</tr>
<tr>
<td height='25'>&nbsp;</td>
<td height='25'>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>";
}
            }
//          else{
//              echo "<td>&nbsp;</td>"; //If there are no more records at the end, add a blank column
            }
//      }
//  } 

while($row);
    echo "</table>";

?>
</tr>
</tbody>
</table>
2

There are 2 best solutions below

0
On

The reason your products are printing

AAA

BBB

CCC

...

Is because your running a for loop on the same SQL data and the SQL data isn't changing until the while loop executes again, hence the while($row) that you are using.

You will have to do something like the following:

$counter = 0; 
echo "<table>";
while($row = mysql_fetch_assoc($result))
{
if($counter == 0){echo "<tr>"; }
echo "<tr>";
echo "<td>";
echo $row[yourProductData]//call your product data here
....
echo "</td>";
echo "</tr>";
$counter++;
if($counter == 4){echo "</tr>"; $counter= 0;}
}
echo"</table>";

Somthing simple like that should be a better and less confusing format to get

ABC

DFG

...

0
On

I finally figured this out and just wanted to share in case it could help someone else. The code I needed to get around jumi is as follows:

<?php $document = &JFactory::getDocument();
$renderer   = $document->loadRenderer('modules');
$position   = 'connmenu';
$options   = array('style' => 'raw');
echo $renderer->render($position, $options, null);?>