I want to get data from the MySQL database and put it in an a.php file with my table. I want to display the title, text, and attachment ($name) for the user to download in each row of my table. The issue is that every table entry in the my.php file that has a table displays a list of all attachments from the database when I try to display that. Therefore, I only want to display one attachment per database entry that shares the same ID as the row's title and text.
This is my database table:
CREATE TABLE IF NOT EXISTS `table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`text` varchar(30) NOT NULL,
`name` varchar(30) NOT NULL,
`type` varchar(30) NOT NULL,
`size` int(11) NOT NULL,
`content` longblob NOT NULL,
PRIMARY KEY (`id`) )
My code:
<?php
include('config.php');
$sqlget="SELECT * FROM table ORDER BY timestamp DESC";
$sqldata= mysqli_query($dbcon, $sqlget) or die ('error');
echo"<table>";
while ($row=mysqli_fetch_array($sqldata,
MYSQLI_ASSOC)) {
echo "<tr><td>";
echo"<b><font color='#DF01A5'> Title: ".$row['title']."</font></b>";
echo "<br/>";
echo $row['text'];
echo "<br/>";
echo "<b><font color='#DF01A5'>Attachment: </font>";
?>
<?php
$con = mysql_connect('localhost', 'root', 'pass') or die(mysql_error());
$db = mysql_select_db('database', $con);
$query = "SELECT id, name FROM table";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php echo urlencode($id);?>"
><?php echo urlencode($name);?></a> <br>
<?php
}
}
mysql_close();
echo"</table";
?>
Can someone help me with this?