Displayng N/A in a table cell when mySQL cell is empty
Moderator: General Moderators
Displayng N/A in a table cell when mySQL cell is empty
Hi
I am building a table which shows ".pdf" as a link to a file showing the results of a race. However if no race has taken place there will be no file to link to and I want the cell to read "N/A" or as a last resort to just be blank.
I have tried this in dreamweaver to no avail as the option are show if recordset is empty and show if recordset is not empty. The recordset wont be empty as it has already picked up that there is a racename and an overall result plus details of race 1 as a minimum as nothing will be added until the first race is run.
I have put the code at the bottom for this table which is at its bare minimum and i think i need to have code inside each TD tag (except for the first three TD lines) to say if mySQL race2 (etc) is full then the HTML code reads as it does below else if it is empty then write N/A inside the TD tags.
Can anyone provide this code I am so new and have tried but cant do it properly.
Thank you very much.
Syvers
<table border="1">
<tr>
<td>RaceName</td>
<td>Result</td>
<td>Race1</td>
<td>Race2</td>
<td>Race3</td>
<td>Race4</td>
<td>Race5</td>
<td>Race6</td>
<td>Race7</td>
<td>Race8</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['RaceName']; ?></td>
<td><a href="result/<?php echo $row_Recordset1['Result']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race1']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race2']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race3']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race4']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race5']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race6']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race7']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race8']; ?>">.pdf</a></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
I am building a table which shows ".pdf" as a link to a file showing the results of a race. However if no race has taken place there will be no file to link to and I want the cell to read "N/A" or as a last resort to just be blank.
I have tried this in dreamweaver to no avail as the option are show if recordset is empty and show if recordset is not empty. The recordset wont be empty as it has already picked up that there is a racename and an overall result plus details of race 1 as a minimum as nothing will be added until the first race is run.
I have put the code at the bottom for this table which is at its bare minimum and i think i need to have code inside each TD tag (except for the first three TD lines) to say if mySQL race2 (etc) is full then the HTML code reads as it does below else if it is empty then write N/A inside the TD tags.
Can anyone provide this code I am so new and have tried but cant do it properly.
Thank you very much.
Syvers
<table border="1">
<tr>
<td>RaceName</td>
<td>Result</td>
<td>Race1</td>
<td>Race2</td>
<td>Race3</td>
<td>Race4</td>
<td>Race5</td>
<td>Race6</td>
<td>Race7</td>
<td>Race8</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['RaceName']; ?></td>
<td><a href="result/<?php echo $row_Recordset1['Result']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race1']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race2']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race3']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race4']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race5']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race6']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race7']; ?>">.pdf</a></td>
<td><a href="result/<?php echo $row_Recordset1['Race8']; ?>">.pdf</a></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
-
Paddy
- Forum Contributor
- Posts: 244
- Joined: Wed Jun 11, 2003 8:16 pm
- Location: Hobart, Tas, Aussie
- Contact:
Just an example for race 8. The rest will be the same.
Code: Select all
<?php
<td><a href="result/<?php if ($row_Recordset1['Race8'] == "") { echo ("N/A"); } else { echo ($row_Recordset1['Race8'].".pdf"); } ?>"></a></td>
?>I have also just realised something that would produce the page wrong as the code would make N/A a link.
Should the code be something straight after the TD tag such as:-
If ($row_Recordset1['Race8'] == "") echo N/A else echo <a href="result/<?php if ($row_Recordset1['Race8'].".pdf")
I am unsure of the syntax and dont want to get even further confused so havent actullay tried it.
Thanks
Should the code be something straight after the TD tag such as:-
If ($row_Recordset1['Race8'] == "") echo N/A else echo <a href="result/<?php if ($row_Recordset1['Race8'].".pdf")
I am unsure of the syntax and dont want to get even further confused so havent actullay tried it.
Thanks
Paddy missed something
Code: Select all
<td>
<?php
if ($row_Recordset1['Race8'] == "") {
echo "N/A";
} else{
echo "<a href="result/{$row_Recordset1['Race8']}.pdf">PDF</a>";
}
?>
</td>