Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将MySQL请求结果放入表中_Php_Mysql_Html Table - Fatal编程技术网

Php 将MySQL请求结果放入表中

Php 将MySQL请求结果放入表中,php,mysql,html-table,Php,Mysql,Html Table,您的代码中有一些访问括号: <?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 pr

您的代码中有一些访问括号:

<?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>";
} 
?>
$result=mysql\u query(“按用户id从产品中选择*,其中产品类型='weddingdressaline'订单”);

{首先,为了每个人,请学习一些干净的编码标准:

第二个问题是,您的输出错误。尝试将表用于其中一个(使用div)只是这些天糟糕的标记。您的所有样式都应该在CSS中,而不是嵌入到页面中

这是您大大改进的标记。您可以使用CSS来更改它在页面上的显示方式,而不是表结构

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


“problwm”…它不允许您使用“problem”是有原因的,不要绕过规则,
while($row=mysql\u fetch\u array($result)){…}
部分对每个项都执行。此外,
while($i<3){…}
part in负责将该项复制3次。因此,这就是你的问题所在。哇,大写标记和属性。刚刚回顾了1999年。更不用说它们没有全部关闭,表中有一个表,以及不推荐的元素/属性……哦,天哪!我没有收到这样的评论:PHP解释器不关心广告附加括号,对吗?这仍然是一种难看的编码方式,更不用说非常混乱。它是否有效。@pthurmond true,我只是想知道它是否不仅仅意味着这些。@Legolas:它不会修改当前的作用域吗?
<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>