0
echo "<br><table><tr>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    if ($j == 2) echo '<tr>';
    echo    '<td width="50%" valign="top"><strong>' . $row['name'] .
            '</strong><br><strong>Price:</strong> £' . $row['price'] .
            '<br><strong>Stock:</strong> ' . $row['stock'] . ' units' .
            '<br><img src="upload/' . $row['imgName'] .
            '" width="100em" height="100em" /><br><br>' . $row['descr'] .
            '<br><a href="added.php?id="' . $row['P_id'] . '">Add to Cart</a></td>';
    $j++;
}

有问题的元素是

$row['P_id']

P_id 的背景信息:

  • 它是 products 表的主键
  • 我什至无法呼应它的价值?

编辑

按照要求 :)

$query = "SELECT * FROM products WHERE prodGroup='$prodGroups[0]'"; // GET PRODUCTS FROM FIRST PRODUCT GROUP
$result = mysql_query($query);

编辑

$query = "CREATE TABLE products (
    P_id INT AUTO_INCREMENT NOT NULL KEY,
    name VARCHAR(128) NOT NULL,
    price DECIMAL(5,2) UNSIGNED NOT NULL,
    descr TEXT,
    imgName VARCHAR(50),
    stock INT UNSIGNED NOT NULL DEFAULT '0',
    prodGroup VARCHAR(128) NOT NULL
)";
4

1 回答 1

1

删除 id= 之后的 " 并重试。

<a href="added.php?id="' . $row['P_id'] . '">Add to Cart</a>

应该

<a href="added.php?id=' . $row['P_id'] . '">Add to Cart</a>
于 2013-04-30T19:12:30.813 回答