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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.