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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
syvers
Forum Newbie
Posts: 5
Joined: Sat Nov 15, 2003 2:16 pm

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

Post 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>
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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> 
?>
syvers
Forum Newbie
Posts: 5
Joined: Sat Nov 15, 2003 2:16 pm

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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?
syvers
Forum Newbie
Posts: 5
Joined: Sat Nov 15, 2003 2:16 pm

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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>
syvers
Forum Newbie
Posts: 5
Joined: Sat Nov 15, 2003 2:16 pm

Post by syvers »

Paddy, you are a star.

Thank you very much for your help, very appreciated.

Syvers
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

No, no! I'm a star, not Paddy :D
syvers
Forum Newbie
Posts: 5
Joined: Sat Nov 15, 2003 2:16 pm

Post by syvers »

Oops sorry, you both are :roll:
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Bah, you're a bit of space dust compared to me. ;)
Post Reply