Page 1 of 1

Displayng N/A in a table cell when mySQL cell is empty

Posted: Sat Nov 15, 2003 2:16 pm
by syvers
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>

Posted: Sat Nov 15, 2003 3:36 pm
by Paddy
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> 
?>

Posted: Sat Nov 15, 2003 3:52 pm
by syvers
Thnaks, unfortunately it displays nothing in the table cells, neither the .pdf link or n/a.

It certainly looks like it should work

Posted: Sat Nov 15, 2003 3:58 pm
by Paddy
That TD is meant to be one line. Have you got that? I can't see why it won't work. Do a bit of trouble shooting. Take out the else for now and see if that works properly without it. I assume it printed out race 8 correctly before?

Posted: Sat Nov 15, 2003 3:58 pm
by syvers
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

Posted: Sat Nov 15, 2003 3:59 pm
by Weirdan
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>

Posted: Sat Nov 15, 2003 4:03 pm
by syvers
Paddy, you are a star.

Thank you very much for your help, very appreciated.

Syvers

Posted: Sat Nov 15, 2003 4:06 pm
by Weirdan
No, no! I'm a star, not Paddy :D

Posted: Sat Nov 15, 2003 4:10 pm
by syvers
Oops sorry, you both are :roll:

Posted: Sat Nov 15, 2003 4:10 pm
by Paddy
Bah, you're a bit of space dust compared to me. ;)