msei Posted April 6, 2009 Share Posted April 6, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
AmandaF Posted April 6, 2009 Share Posted April 6, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.