Reputation: 145
Hello im new to php but i cant make this dynamiclist to work here is the code..
<?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();
?>
It is getting the correct id from the url but the query isnt working for me thx for any answers!
Upvotes: 2
Views: 76
Reputation: 506
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);
?>
Upvotes: 1
Reputation: 51
Try
to usr mysql_fetch_array($sql,MYSQL_ASSOC)
or mysql_fetch_assoc($sql)
instead of mysql_fetch_array($sql)
By default mysql_fetch_array return non associative array.
Pay attention:
Do not SELECT * FROM table_name
. It's better for performance to use SELECT column1, colum2 FROM table_name
Mysql module is deprecated. It's better to use PDO mysql module page MySQL API comparison
Upvotes: 1