0

我是 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";
}
4

2 回答 2

0

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

在每个中替换这个,

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

有了这个

echo "<table border=1 class=\"inlineTable\" style=\"width:50%;float:left;\">\n"; 
于 2013-07-26T20:41:54.330 回答
0

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

标签并用单独的元素替换它们,<td>对齐应该没问题。$prodcatSQL="从 prodcat 中选择 prodcatid、prodcatname、prodcatimage"; // 创建一个 $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 输出编辑到问题中。

于 2013-07-26T20:48:45.847 回答