我开始构建一个非常简单的产品展示系统,主要是为了建立我自己的技能,但也可以在我的网站上使用。
list.php的
<html>
<head>
<title>Retrieve data from the database</title>
<?php
$username='';
$password='';
$database='';
?>
</head>
<body>
<ul>
<?php
// Connect to database server
mysql_connect(localhost,$username,$password);
// Select database
@mysql_select_db($database) or die( 'Unable to select database');
// SQL query
$sql = "SELECT * FROM products WHERE category = 30";
// Execute the query (the recordset $rs contains the result)
$result = mysql_query($sql);
// Loop the recordset $rs
while($row = mysql_fetch_array($result)) {
// Name of the person
$strName = $row['make'];
// Create a link to person.php with the id-value in the URL
$strLink = "<a href = 'product.php?id = " . $row['ID'] . "'>" . $strName . "</a>";
// List link
echo "<li>" . $strLink . "</li>";
}
// Close the database connection
mysql_close();
?>
</ul>
</body>
</html>
Product.php
<html>
<head>
<title>Retrieve data from database</title>
</head>
<body>
<?php
$username="";
$password="";
$database="";
// Connect to database server
mysql_connect(localhost,$username,$password);
// Select database
@mysql_select_db($database) or die( "Unable to select database");
// Get data from the database depending on the value of the id in the URL
$sql = mysql_query('SELECT * FROM products WHERE ID=' . $_GET["ID"]);
$result = mysql_query($sql);
if(!$result)
die(mysql_error());
// Loop the recordset
while($row = mysql_fetch_array($result)) {
// Write the data of the product
echo $row['category'];
echo "<p>";
echo $row["make"];
echo "<p>";
echo $row["description"];
echo "<p>";
echo $row["picture"];
}
// Close the database connection
mysql_close();
?>
<p><a href="list.php">Return to the list</a></p>
</body>
</html>
可以看到弄乱HERE
如果有人可以帮我解决这个问题,我将非常感激!
答案 0 :(得分:0)
尝试这种方式,但不完全确定这个顽固的问题。您可以尝试使用$_GET
array_change_key_case()
数组的所有键的大小写更改为小写
$get = array_change_key_case($_GET);
$id = $get['id'];
$sql = mysql_query('SELECT * FROM products WHERE ID=' . $id);
NB:首先确定SELECT * FROM products WHERE ID=your_row_id
是否返回结果?
答案 1 :(得分:0)
我发现页面'list.php'生成的链接格式不正确。
改变了这个:
$strLink = "<a href = 'product.php?id = " . $row['ID'] . "'>" . $strName . "</a>";
到
$strLink = "<a href = 'product.php?id=".$row['ID']."'>" . $strName . "</a>";
它现在正如它应该的那样工作!