How to "not show" blank fields in ads script

Discussion in 'PHP' started by ian_batten, Feb 7, 2007.

  1. #1
    Hello all,
    I have a general query on an ad script I have altered. Basically, it is a little like a guestbook script...and I was wondering if there was some coding I could do, so that if a field was not filled in, it would not be shown on the index file?
    You can see here:

    http://insectstore.com/classifieds/

    The "add insect add" link goes to the sign page, and you will see there are various fields to fill out.
    You will also see on the ads page, there are lot of ads which have blank fields in. It is these I want to be hidden, if they are not filled in.
    Thanks in advance!
     
    ian_batten, Feb 7, 2007 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can certainly change the script so that it does not display placeholders for empty fields. If the field is not empty, show that bit, otherwise do not.

    This is easier to accomplish if the HTML for the listings is created in your script as it assembles the information from the database. It is more problematic in a template unless you are using a templating system which allows conditionals.

    I cannot offer more concrete suggestions without knowing how you get from the database to the page displayed to visitors.
     
    clancey, Feb 7, 2007 IP
  3. jumpenjuhosaphat

    jumpenjuhosaphat Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is there anyway you could show the script for displaying the ads?
     
    jumpenjuhosaphat, Feb 8, 2007 IP
  4. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can do something like this, for example for the website field (but I would need to see your script to give you the exact answer)
    <?php if ($website) : ?>
      <tr>
        <td><b>Website:</b></td>
        <td><?php echo $website ?></td>
      </tr>
    <?php endif ?>
    PHP:
    (obviously you need to substitute '$website' with the correct variable name in your script, and do this for all the fields that are shown)

    HTH, cheers! :)
     
    picouli, Feb 8, 2007 IP
  5. ian_batten

    ian_batten Well-Known Member

    Messages:
    1,991
    Likes Received:
    106
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Okay, thanks for your input all. I will get the script when I am back at home, and show you where the origin of the index and publish file is...and give that above suggestion a go!
    Thanks again people.
     
    ian_batten, Feb 9, 2007 IP