Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,492 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,714 people online right now. Registration is fast and FREE... Join Now!




correct way to set up if statement

 
Reply to this topicStart new topic

correct way to set up if statement

capty99
6 Mar, 2008 - 08:18 PM
Post #1

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,164



Thanked: 16 times
Dream Kudos: 550
My Contributions
alright... so i have my db call, along with an if statement that checks to make sure there is a result... if there is... then i output my page.

however, i want to do only output sections depending on what rows exist and what don't ...

what is the correct way to set this up :

so i pull address from the db..

php

if ($row-> address == NULL)
{
}
else
{
<div> all of my crap i want to output </div>
}


i've tried a couple ways with that top if statment, exists... setting the address == '' ....

any help on the correct way to do that would be appreciated.
User is offlineProfile CardPM
+Quote Post

capty99
RE: Correct Way To Set Up If Statement
6 Mar, 2008 - 08:35 PM
Post #2

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,164



Thanked: 16 times
Dream Kudos: 550
My Contributions
boom... tyler's new way of solving problems :
posting it and then realizing hes an idiot .... hooray!

i was just calling the wrong variable from the list , address instead of caddress.
hooray.

correct code for anyone else that happens upon it :
php

<? if ($row-> caddress == ""){ } else { ?>
your code goes here
<? } ?>

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Correct Way To Set Up If Statement
7 Mar, 2008 - 07:39 AM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
*YAY!* Congrats. Glad to see that you have it working.
User is online!Profile CardPM
+Quote Post

c0mrade
RE: Correct Way To Set Up If Statement
9 Mar, 2008 - 10:27 AM
Post #4

D.I.C Head
**

Joined: 16 Nov, 2007
Posts: 111



Thanked: 1 times
My Contributions
Just a tip, but when mixing html and php it's conventional to use the php alternate syntax for readability.

Instead of:
php

<?php if ($row-> caddress == "") { ?>
your code goes here
<?php } else { ?>
your code goes here
<?php } ?>


You can do:
php

<?php if ($row-> caddress == "") : ?>
your code goes here
<?php else : ?>
your code goes here
<?php endif; ?>

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:46PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month