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] Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/ 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 } ?> Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-299976 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? Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-299983 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. Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-299991 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-299992 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. Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-300092 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>'; Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-300093 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? Link to comment https://forums.phpfreaks.com/topic/60303-another-logic-problem/#findComment-300161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.