So, I have a database table with the following fields: title, date, text, file1, file2, file3, file4, file5. I use it to store news and occasionally, the title of files related to the news. The problem is that different news have a different number of files, ranging from 0 to 5. Now, how can I post the link to the exact number of files every news contain? I tried something like this but it didn’t work:
$query="SELECT * FROM news WHERE id=1";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
extract($row);
for($i=1;$i<=5;$i++)
if($"file".$i!="")?>
<p><a href="/admin/uploads/<?php echo $"file".$i?>"><?php echo $"file".$i?></a></p>
}
I think this is what you want: