Forums

PHP

This topic is locked

if statement - Null values

Posted 23 Apr 2004 11:00:04
1
has voted
23 Apr 2004 11:00:04 Dave Desormeaux posted:
Please help!

I'm doing a site for a company that wants to list their clients, a description of their work with that client and testimonials from those clients (where applicable).


I have set up the page that currently displays the following:

Client Name
Description of company's work with the client.Description of company's work with the client.Description of company's work with the client.
Client Testimonial

Client Name
Description of company's work with the client.Description of company's work with the client.Description of company's work with the client.
Client Testimonial

etc.

"Client Name" will link to the client's web site.
"Client Testimonial" will link to a page displaying the text of their testimonial.

However,not all clients have testimonials.


My problem is:

How do I create an IF ELSE statement that will display the "Client Testimonial" link ONLY if it exists in the database? In other words, when the field "clientURL" in the db is null, the "Client Testimonial" link will not be displayed on the page.

This is the current code.

<?php do { ?>
<p><a href="<?php echo $row_rsClients['clientURL']; ?>" target="_blank"><?php echo $row_rsClients['client_org']; ?></a><br>
<?php echo $row_rsClients['client_blurb']; ?><br>
Client Testimonial</p>
<?php } while ($row_rsClients = mysql_fetch_assoc($rsClients)); ?>

Thanks.

Dave

Replies

Replied 23 Apr 2004 16:55:25
23 Apr 2004 16:55:25 Andrew Paget replied:
Im not sure which piece of your code you want to "mute" but this should help

<pre id=code><font face=courier size=2 id=code>
&lt;?php if($row_rsClients['clientURL'] != '') { ?&gt;
Display this if it is not empty.
&lt;?php } ?&gt;
</font id=code></pre id=code>
Replied 23 Apr 2004 17:09:21
23 Apr 2004 17:09:21 Dave Desormeaux replied:
Thanks Manicsurfer!

Works great. I was missing the exclamation mark (what does that do?)

Here's the new code for anyone following the thread:

&lt;?php do { ?&gt;
&lt;p&gt;
&lt;?php if($row_rsClients['clientURL'] != '') { ?&gt;
&lt;?php echo $row_rsClients['client_org']; ?&gt;&lt;br&gt;
&lt;?php } else {?&gt;
&lt;a href="&lt;?php echo $row_rsClients['clientURL']; ?&gt;" target="_blank"&gt;&lt;?php echo $row_rsClients['client_org']; ?&gt;&lt;/a&gt;&lt;br&gt;
&lt;?php } ?&gt;
&lt;?php echo $row_rsClients['client_blurb']; ?&gt;&lt;br&gt;
Comments&lt;/p&gt;
&lt;?php } while ($row_rsClients = mysql_fetch_assoc($rsClients)); ?&gt;
Replied 23 Apr 2004 19:05:00
23 Apr 2004 19:05:00 Dale Stevenson replied:
The ! in != means "not"

BTW I posted before on a collegues account ^^

Edited by - Bloodshot on 23 Apr 2004 19:29:53

Reply to this topic