两个PHP表并排

时间:2013-07-26 20:38:03

标签: php html-table alignment center

我是PHP新手;请帮帮我。

我正在尝试将两个PHP表并排放在一起,但是它们在另一个下方显示一个。我希望在一个标题下并排放置两个桌子,在第二个标题下并排放置两个桌子。我在HTML中看到了一些解决方案,但我正在寻找PHP。请在下面找到我的错误和我的代码的屏幕截图:

请随时要求澄清。

$prodcatSQL="select prodcatid, prodcatname, prodcatimage from prodcat"; // create an $sql variable and store the sql statement

$exeprodcatSQL=mysql_query($prodcatSQL) or die (mysql_error());

while ($arrayprod=mysql_fetch_array($exeprodcatSQL))


{

    echo "<strong>Using display: inline-block; </strong><br>\n"; 
    echo "<table border=1 class=\"inlineTable\">\n"; 
    echo "<tr>\n"; 
    echo "<td><p><a href=products.php?u_prodcatid=".$arrayprod['prodcatid'].">";
    echo $arrayprod['prodcatname'];
    echo "<p><img src=images/".$arrayprod['prodcatimage']."></p>";
    echo "</a></p></td>\n";
    echo "</tr>\n";
    echo "</table>\n";
}


echo "<h3><center>".$subheading."</center></h3>"; 

$treatcatSQL="select treatcatid, treatcatname, treatcatimage from treatcat"; // create an $sql variable and store the sql statement

$exetreatcatSQL=mysql_query($treatcatSQL) or die (mysql_error());

while ($arrayprod=mysql_fetch_array($exetreatcatSQL))


{


    echo "<strong>Using display: inline-block; </strong><br>\n"; 
    echo "<table border=1 class=\"inlineTable\">\n"; 
    echo "<tr>\n"; 
    echo "<td><p><a href=treatmentpackages.php?u_treatcatid=".$arrayprod['treatcatid'].">";
    echo $arrayprod['treatcatname'];
    echo "<p><img src=images/".$arrayprod['treatcatimage']."></p>";
    echo "</a></p></td>\n";
    echo "</tr>\n";
    echo "</table>\n";
}

2 个答案:

答案 0 :(得分:0)

如果您不想要外部CSS,则需要将其添加到表中

在每个中替换它,

echo "<table border=1 class=\"inlineTable\">\n"; 

有了这个

echo "<table border=1 class=\"inlineTable\" style=\"width:50%;float:left;\">\n"; 

答案 1 :(得分:0)

您有嵌套<p>标签,可能会引入不必要的新行。删除

标记并将其替换为单独的<td>元素,并且对齐应该没问题。     $ prodcatSQL =“选择prodcatid,prodcatname,prodcatimage from prodcat”; //创建一个$ sql变量并存储sql语句

$exeprodcatSQL=mysql_query($prodcatSQL) or die (mysql_error());

while ($arrayprod=mysql_fetch_array($exeprodcatSQL))


{
    echo "<strong>Using display: inline-block; </strong><br>\n"; 
    echo "<table border=1 class=\"inlineTable\">\n"; 
    echo "<tr>\n"; 
    echo "<td><a href=products.php?u_prodcatid=".$arrayprod['prodcatid'].">";
    echo $arrayprod['prodcatname'];
    echo "</a></td><td><a href=products.php?u_prodcatid=".$arrayprod['prodcatid']."><img src=images/".$arrayprod['prodcatimage'].">";
    echo "</td></a>\n";
    echo "</tr>\n";
    echo "</table>\n";
}
$treatcatSQL="select treatcatid, treatcatname, treatcatimage from treatcat"; // create an $sql variable and store the sql statement

$exetreatcatSQL=mysql_query($treatcatSQL) or die (mysql_error());

while ($arrayprod=mysql_fetch_array($exetreatcatSQL))


{


    echo "<strong>Using display: inline-block; </strong><br>\n"; 
    echo "<table border=1 class=\"inlineTable\">\n"; 
    echo "<tr>\n"; 
    echo "<td><a href=treatmentpackages.php?u_treatcatid=".$arrayprod['treatcatid'].">";
    echo $arrayprod['treatcatname'];
    echo "</a></td><td><a href=treatmentpackages.php?u_treatcatid=".$arrayprod['treatcatid'].">";
    echo "<img src=images/".$arrayprod['treatcatimage']."></a>";
    echo "</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
}

如果这不起作用,请将HTML输出编辑到问题中。