从左到右读取的PHP代码

时间:2015-09-02 19:57:48

标签: php joomla jumi

之前我使用过此代码的一个版本,它会像我们应该的那样从左到右吐出我的内容。我无法通过这种方式阅读新项目并寻求一些帮助。它读作:

A A A
B B B
C C C

而不是

A B C
D E F

这是一个链接,它的外观和代码,任何帮助将不胜感激,谢谢。

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>

3 个答案:

答案 0 :(得分:0)

您的产品正在打印的原因

AAA

BBB

CCC

...

是因为你在相同的SQL数据上运行for循环,并且在while循环再次执行之前SQL数据没有改变,因此你正在使用while($ row)。

您必须执行以下操作:

$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>";

这样简单的事情应该是一个更好,更少混乱的格式来获得

ABC

DFG

...

答案 1 :(得分:0)

感谢您提供的信息。稍微调整一下,我就能让它上班,但它让我陷入了最后一道障碍。

我通过Joomla和插件Jumi运行这个我试图让我的装载标签工作,但它不会,我有一种感觉Jumi与问题有关。任何帮助都将非常感激,因为我需要这样做才能让人们可以浏览多个产品页面,这就是这个装载模块为我们网站所做的工作。

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

$query = "SELECT * FROM products WHERE page = '1' ORDER BY name";


$result = mysql_query($query) or die(mysql_error());
	
?>
<?
$i = 0; 
while($row = mysql_fetch_assoc($result))
{
if($i == 0){echo "<tr valign='top'>"; }
echo "<td>";
echo "<a href='$row[link]'"?> onclick="_gaq.push(['_trackEvent', 'Clicks', 'Connectors', '<?php echo "$row[name]"?>']);"><? echo "<img style='border: #015d90 1px solid;' alt='$row[name]' src='/$row[image]' height='74' width='120' border='0' /></a></td>				
<td width='2'>&nbsp;</td>
<td><span style='font-family: andale mono,times; font-size: 8pt; line-height:15px;'><b>$row[name]:</b> $row[description]</span></td>
<td><span style='font-family: andale mono,times; font-size: 8pt; line-height:15px;'><b>&nbsp;</b></span>";
echo "</td>";
$i++;
if($i == 3){echo "</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>"; $i= 0;}
}
echo"</tbody>";
echo"</table>";
?>
<p style="text-align: center;"><br />{loadposition connmenu}</p>

答案 2 :(得分:0)

我终于想出了这个,只是想分享,以防它可以帮助别人。我需要解决jumi的代码如下:

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