Jump to content

Display record


msei

Recommended Posts

Hi I am new using php and I am having a little problem the way the download link is displayed. What I want to do is to do not display the link download when there is nothing to download but I do still want the info from that record to be displayed. Any help will be appreciated. Thank you in advance.

 


if($result) 
{

    if(mysqli_num_rows($result) == 0) {
        echo "<p>There are no files in the database</p>";
    }
    else
    {
        echo "<table width='100%'><tr>";		  
echo "<td><b>Institution</b></td>";
        echo "<td><b>Website</b></td>";
        echo "</tr>";

        while($row = mysqli_fetch_assoc($result))
        {
            echo "<tr><td>". $row['SYEinstitution']. "</td>";
            echo "<td>". $row['SYEwebsite']. "</td>";
            echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>";
            echo "</tr>";  
        }
         echo "</table>";
    }
   mysqli_free_result($result);
}
else 
{
    echo "Error! SQL query failed:";
    echo "<pre>". $dbLink->error ."</pre>";
}
mysqli_close($dbLink);
?>

Link to comment
https://forums.phpfreaks.com/topic/152813-display-record/
Share on other sites

This isn't really a regex issue.  You just need to put the download link inside an if statement that has a condition checking if the file can be downloaded.  Something like:

 

if($row['FileID'])

{

echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>";

}

else

{

echo '<td></td>';

}

 

(Of course, that assumes that the FileID evaulates to false if there's no file.  If that's not the case, you'll need to change it to whatever it should be.)

 

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/152813-display-record/#findComment-802739
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.