Jump to content

Another logic problem


lc21

Recommended Posts

hi, I am currently displaying data from a database as follows, however I would like to be able to add another column to the table which displays  a button so a user can download a file that is related to that record, however there is not always a file available which is indicated in the database as either yes or no. If it is yes i would like the download link to be displayed in the new column as a button or left blank if no file has been uploaded.

 

I was just wondering how this could be done? thank you

 


<?php
while($display=mysql_fetch_array($query))
{
     echo "<tr><td>".$display['problemId']."</td><td>".$display['name']."</td></tr>";
}
?>
[/coded]

Link to comment
Share on other sites

<?php
while($display=mysql_fetch_array($query))
{
     if (empty($display['problemFile'])) {
          $file = NULL;
     }
     else {
          $file = "<td>".$display['problemFile']."</td>";
     }
     
     echo "<tr><td>".$display['problemId']."</td><td>".$display['name']."</td>".$file."</tr>";
}
?>

Link to comment
Share on other sites

<?php
while($display=mysql_fetch_array($query))
{
     if (empty($display['problemFile'])) {
          $file = NULL;
     }
     else {
          $file = "<td>".$display['problemFile']."</td>";
     }
     
     echo "<tr><td>".$display['problemId']."</td><td>".$display['name']."</td>".$file."</tr>";
}
?>

 

So what happens when some rows have a file, and some dont? Your table would not be valid html.

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.