SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    If Blank Do Not Echo?

    Hi,

    I have a code which enables someone to submit a maximum of 3 resource requirements. For example if they require computers, desks and fire extinguishers it will display 3 cells with the details. However if they only require computers and desks it will display an empty cell for the third unused requirement.

    What I would like to do is say IF blank do not echo. Would I use something this?


    Code:
    if ($supplier3 <> "") {

    Code:
     <div class="resourceprofilerequirementbox">
    			    <div class="resourceprofilerequirementheader">
    			   Resource Requirements
    			   </div>
    			   <div class="resourceprofilerequirement">
    			    <div class="resourceprofilesupplier">
    		<?php echo (!empty($row['supplier1'])) ? $row['supplier1'] : ''; ?>
    	</div>
    						    <div class="resourceprofilebudget">
    		Requirements: </div>
    		<div class="resourcesupplierdetails">
    		<?php echo (!empty($row['supplierdetails1'])) ? $row['supplierdetails1'] : ''; ?>
    	</div>
    				    <div class="resourceprofilebudget">
    		Budget: <?php echo (!empty($row['budget1'])) ? $row['budget1'] : ''; ?>
    	</div>
    		</div>
    		
    					   <div class="resourceprofilerequirement">
    			    <div class="resourceprofilesupplier">
    			<?php echo (!empty($row['supplier2'])) ? $row['supplier2'] : ''; ?>
    	</div>
    						    <div class="resourceprofilebudget">
    		Requirements: </div>
    			<div class="resourcesupplierdetails">
    		<?php echo (!empty($row['supplierdetails2'])) ? $row['supplierdetails2'] : ''; ?>
    	</div>
    				    <div class="resourceprofilebudget">
    		Budget: <?php echo (!empty($row['budget2'])) ? $row['budget2'] : ''; ?>
    	</div>
    		</div>
    	
    					   <div class="resourceprofilerequirement">
    			    <div class="resourceprofilesupplier">
    			<?php echo (!empty($row['supplier3'])) ? $row['supplier3'] : ''; ?>
    	</div>
    						    <div class="resourceprofilebudget">
    		Requirements: </div>
    			<div class="resourcesupplierdetails">
    		<?php echo (!empty($row['supplierdetails3'])) ? $row['supplierdetails3'] : ''; ?>
    	</div>
    				    <div class="resourceprofilebudget">
    		Budget: <?php echo (!empty($row['budget3'])) ? $row['budget3'] : ''; ?>
    	</div>
    		</div>

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    you've already got an example of this in your code.

    PHP Code:
            <?php echo (!empty($row['supplier1'])) ? $row['supplier1'] : ''?>
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    So how would I insert all of this block into the cell that says if there is content I would say to echo it.

    I thought I would need an if (if blank do not echo) and else (else do echo).

    Code:
    					   <div class="supplierprofilerequirement">
    			    <div class="supplierprofilesupplier">
    			<?php echo (!empty($row['supplier3'])) ? $row['supplier3'] : ''; ?>
    	</div>
    						    <div class="supplierprofilebudget">
    		Requirements: </div>
    			<div class="suppliersupplierdetails">
    		<?php echo (!empty($row['supplierdetails3'])) ? $row['supplierdetails3'] : ''; ?>
    	</div>
    				    <div class="supplierprofilebudget">
    		Budget: <?php echo (!empty($row['budget3'])) ? $row['budget3'] : ''; ?>
    	</div>
    		</div>

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,825
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Okay, look at it one at a time: Here is what you have
    PHP Code:
     <div class="resourceprofilerequirementbox">
                    <div class="resourceprofilerequirementheader">
                   Resource Requirements
                   </div>
                   <div class="resourceprofilerequirement">
                    <div class="resourceprofilesupplier">
            <?php echo (!empty($row['supplier1'])) ? $row['supplier1'] : ''?>
        </div>
                                <div class="resourceprofilebudget">
            Requirements: </div>
            <div class="resourcesupplierdetails">
            <?php echo (!empty($row['supplierdetails1'])) ? $row['supplierdetails1'] : ''?>
        </div>
                        <div class="resourceprofilebudget">
            Budget: <?php echo (!empty($row['budget1'])) ? $row['budget1'] : ''?>
        </div>
            </div>
    You want to conditionally, skip writing this entire output if the $row['budget1'] is empty and $row['supplierdetails1'] is empty and $row['supplier1'] is empty
    PHP Code:
    <?php if (!empty($row['budget1']) && !empty($row['supplierdetails1']) && !empty($row['supplier1'])) { ?>
     <div class="resourceprofilerequirementbox">
                    <div class="resourceprofilerequirementheader">
                   Resource Requirements
                   </div>
                   <div class="resourceprofilerequirement">
                    <div class="resourceprofilesupplier">
            <?php echo (!empty($row['supplier1'])) ? $row['supplier1'] : ''?>
        </div>
                                <div class="resourceprofilebudget">
            Requirements: </div>
            <div class="resourcesupplierdetails">
            <?php echo (!empty($row['supplierdetails1'])) ? $row['supplierdetails1'] : ''?>
        </div>
                        <div class="resourceprofilebudget">
            Budget: <?php echo (!empty($row['budget1'])) ? $row['budget1'] : ''?>
        </div>
            </div>
    <?php ?>
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    SUPERB! Cheers dude.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •