<?PHP
?>
<html>
<head>
<title></title>
<link rel="stylesheet" href="one.css" type="text/css">
</head>
<?
include_once "db.php";
$result = mysql_query("SELECT * FROM products WHERE product_type='weddingdressaline' ORDER BY user_id");
{
echo "<table width='100%' border='5' bordercolor='#860071' cellspacing='5' cellpadding='5'>";
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
$i = 0;
while ($i < 3)
{
echo '<td><table width="100%" border="0" cellspacing="0" cellpadding="0" BGCOLOR="#AA99C5"><TR><TD><div class="container"><A HREF="viewproduct.php?user_id=' . $row["user_id"] . '"><img src="showimage.php?user_id=' . $row["user_id"] . '" ALIGN="CENTER" /></A></div></td><tr><td><CENTER><STRONG>' . $row['price'] . '</STRONG></td></TABLE>';
$i++;
}
echo "</tr>";
}
} else {
echo "<tr><td colspan='" . ($i + 1) . "'>No Results found!</td></tr>";
}
echo "</table>";
}
?>
代码假设将一个项目放入一列。不幸的是,它为整行放置了一个结果。如果有人有任何想法如何解决这个请帮助。
答案 0 :(得分:1)
您的代码中有一些访问括号:
$result = mysql_query("SELECT * FROM products WHERE product_type='weddingdressaline' ORDER BY user_id");
{ <===
echo "<table width='100%' border='5' bordercolor='#860071' cellspacing='5' cellpadding='5'>";
[....]
echo "</table>";
} <===
答案 1 :(得分:0)
首先,请为每个人学习一些干净的编码标准: http://drupal.org/coding-standards
第二个问题是你输错了。如今,尝试使用表格(使用div)只是糟糕的标记。您的所有样式都应该在CSS中,而不是嵌入在页面中。
这是你大大改进的标记。您使用CSS来更改它在页面上的显示方式,而不是表格结构。
<html>
<head>
<title></title>
<link rel="stylesheet" href="one.css" type="text/css">
</head>
<body>
<?php
include_once "db.php";
$result = mysql_query("SELECT * FROM products WHERE product_type = 'weddingdressaline' ORDER BY user_id");
echo '<div class="productTable">';
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_object($result)) {
echo '
<div class="container">
<div class="productImage">
<a href="viewproduct.php?user_id=' . $row->user_id . '">
<img src="showimage.php?user_id=' . $row->user_id . '" align="center" />
</a>
</div>
<div class="price">' . $row->price . '</div>
</div>';
}
}
else {
echo '<div class="container"><div class="noResults">No Results found!</div></div>';
}
echo "</div>";
?>
</body>
</html>