您好我刚接触php但我不能让这个动态列表在这里工作是代码..
<?php
if (isset($_GET['id'])) {
include "DocumentSystem/scripts/connect_to_mysql.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
$dynamicList = "";
$sql = mysql_query("SELECT * FROM documents WHERE id='$id' LIMIT 1");
$documentCount = mysql_num_rows($sql); // count the output amount
if ($documentCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$document_name = $row["document_name"];
$full_document = $row["full_document"];
$dynamicList .= '<div id="slidepic">
<img src="images/document_images/'.$id.'.jpg" width="550" height="350" />
<div id="slideshow">
<h1> <a href="document.php?id='.$id.'">'.$document_name.'</a></h1>
<br />
<p1><a href="document.php?id='.$id.'">'.$full_document.'</a></p1>
</div>
</div>';
}
} else {
$dynamicList = "We have no documents listed in the database";
}
mysql_close();
?>
它从网址获取正确的ID,但查询不适合我 thx任何答案!
答案 0 :(得分:1)
尝试
使用mysql_fetch_array($sql,MYSQL_ASSOC)
或mysql_fetch_assoc($sql)
代替mysql_fetch_array($sql)
默认情况下,mysql_fetch_array返回非关联数组。
注意:
不要SELECT * FROM table_name
。使用SELECT column1, colum2 FROM table_name
不推荐使用Mysql模块。最好使用PDO mysql module page MySQL API comparison
答案 1 :(得分:1)
请使用您已获得查询结果
<?php
$con = mysql_connect("localhost","username","password");
mysql_select_db("your_database_name", $con);
$result = mysql_query("SELECT * FROM documents WHERE id = '$id' LIMIT 1");
while($row = mysql_fetch_array($result))
{
echo = $row["id"];
echo = $row["document_name"];
echo = $row["full_document"];
}
mysql_close($con);
?>