2

你好,我是 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();
?>

它正在从 url 获取正确的 id,但查询对我不起作用,谢谢任何答案!

4

2 回答 2

1

Please use you have get the query result

<?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);
?>
于 2012-11-30T12:50:49.233 回答
1

尝试使用 usrmysql_fetch_array($sql,MYSQL_ASSOC)mysql_fetch_assoc($sql)代替mysql_fetch_array($sql) 默认情况下 mysql_fetch_array 返回非关联数组。

注意:

  1. 不要SELECT * FROM table_name。使用性能更好SELECT column1, colum2 FROM table_name

  2. 不推荐使用 Mysql 模块。最好使用PDO mysql模块页面 MySQL API对比

于 2012-11-30T12:39:50.713 回答