lc21 Posted July 17, 2007 Share Posted July 17, 2007 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] Quote Link to comment Share on other sites More sharing options...
spode Posted July 17, 2007 Share Posted July 17, 2007 just assign the file to a variable, then just do: <?php $file = whatever; if(isset($file)){ //display file button } else { // dont } ?> Quote Link to comment Share on other sites More sharing options...
lc21 Posted July 17, 2007 Author Share Posted July 17, 2007 I am not sure how t hat would work with the code I posted above as the results are being displayed in a table so how would each file name get in the variable? Quote Link to comment Share on other sites More sharing options...
rlindauer Posted July 17, 2007 Share Posted July 17, 2007 The if statement and the variable assignment should go in the loop. Quote Link to comment Share on other sites More sharing options...
lur Posted July 17, 2007 Share Posted July 17, 2007 <?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>"; } ?> Quote Link to comment Share on other sites More sharing options...
rlindauer Posted July 17, 2007 Share Posted July 17, 2007 <?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. Quote Link to comment Share on other sites More sharing options...
lur Posted July 17, 2007 Share Posted July 17, 2007 So what happens when some rows have a file, and some dont? Your table would not be valid html. Not related to the original problem. // $file = NULL; $file = '<td></td>'; Quote Link to comment Share on other sites More sharing options...
lc21 Posted July 17, 2007 Author Share Posted July 17, 2007 With the fix is it now valid html? 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.