Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

a variation on "show region" - is this possible?

New Here ,
Mar 08, 2010 Mar 08, 2010

Hi all. I have a page of listings pulled from a database which uses the standard "show region is recordset is not empty" server behaviour. This is working fine and if there's no content for a particular field, then this behaviour does what it's supposed to do.

Problem is that each element of the listing has a header (title/name/description...etc etc) and I want to hide the header for any field that doesn't have any content.

OK, I know I can include the header in the table listing and then it would either show or not, depending, but ideally I need to be able to style the header differently from the listing text, and if it's coming in as {rsArtists.artName}

TOPICS
Server side applications
883
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 08, 2010 Mar 08, 2010

<?php if ($row_featured_art['art_caption']!= "") { ; ?>

                    <?php echo $row_featured_comp['art_caption']; ?>

                            <?php } else { };?>

The above could be used with a bit more modification to do what you want.

if the field is NOT empty then show the field

Else show nothing

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2010 Mar 08, 2010

I'm pretty basic with php so bear with me, if you will - could this be modified to apply so that if I have this:

header1

element1

header2

element2

etc etc

that I can use this to stop header1 from showing if element1 is an empty record? Is that what you mean?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 08, 2010 Mar 08, 2010

Yes.

If I give you an example:

Im not sure how you are making this

but something like this

<table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
<?php if ($query['heading1'] != "") {?><th scope="col">Header 1</th><?php } else { };?>
    <th scope="col">Header 2</th>
  </tr>
  <tr>
    <td>bob</td>
    <td>joe</td>
  </tr>
</table>

you will need a row cound somewhere

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2010 Mar 08, 2010

Basically the table I've got looks like this:

<table>

<tr>

          <td><span class="style2">Artist</span></td>

        </tr>

        <tr>

          <td><span class="style8">

            <?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>

              <?php echo $row_DetailRS1['specialPersonName']; ?>

              <?php } // Show if recordset not empty ?></span></span></td>

        </tr>

        <tr>

          <td><span class="style2">Title</span></td>

        </tr>

        <tr>

          <td><span class="style8">

            <?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>

              <?php echo $row_DetailRS1['specialTitle']; ?>

              <?php } // Show if recordset not empty ?></span></span></td>

        </tr>

</table>

If you could show me how to apply your code suggestion to the first one of those, I'd really appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 08, 2010 Mar 08, 2010

Ok the idea is to enclose the part of the table you want to show if there is a record for it.

<table>
<?php if ($row_DetailRS1['specialPersonName'] != "") { ?>
<tr>

          <td><span class="style2">Artist</span></td>

        </tr>

        <tr>

          <td><span class="style8">

            <?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>

              <?php echo $row_DetailRS1['specialPersonName']; ?>

              <?php } // Show if recordset not empty ?></span></span></td>

        </tr>
<?php } else { } ;?>
       
       
<?php if ($row_DetailRS1['specialTitle'] != "") { ?>
        <tr>

          <td><span class="style2">Title</span></td>

        </tr>

        <tr>

          <td><span class="style8">

            <?php if ($totalRows_DetailRS1 > 0) { // Show if recordset not empty ?>

              <?php echo $row_DetailRS1['specialTitle']; ?>

              <?php } // Show if recordset not empty ?></span></span></td>

        </tr>
<?php } else { } ;?>

</table>

PS sorry for my short previous post, was at work. :'( You wont need a row count of any kind.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2010 Mar 08, 2010

Just tried that and it's exactly what I was looking for, thank you so much, really appreciate it. I clearly need to get myself a decent book on PHP to get my head round all this clever stuff like IF ELSE and so on - any recommendations?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 09, 2010 Mar 09, 2010

David Powers has a great book.

http://foundationphp.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2010 Mar 19, 2010
LATEST

I'm trying to make sense of this whole IF ELSE thing and have knocked up a small table with the following code:

<table width="100%">

  <?php if ($row_rsFrontpage['frontpage'] !== "n") { ?><tr>

    <td width="22%" rowspan="4" valign="top"><a href="specialDetails.php?recordID=<?php echo $row_rsFrontpage['specialID']; ?>"><img src="images/<?php echo $row_rsFrontpage['smallphoto']; ?>" alt="" name="smallpic" border="0" id="smallpic" /></a></td>

    <td width="78%" class="style3"><?php if ($totalRows_rsFrontpage > 0) { // Show if recordset not empty ?>

          <?php echo $row_rsFrontpage['specialTitle']; ?>

          <?php } // Show if recordset not empty ?></td>

  </tr>

  <tr>

    <td><?php if ($totalRows_rsFrontpage > 0) { // Show if recordset not empty ?>

          <?php echo $row_rsFrontpage['specialDescription']; ?>

      <?php } // Show if recordset not empty ?></td>

  </tr>

  <tr>

    <td> </td>

  </tr>

  <tr>

    <td><strong>THIS IS AN UNBEATABLE AUCTION PRIZE! </strong><a href="specialDetails.php?recordID=<?php echo $row_rsFrontpage['specialID']; ?>">More&gt;</a></td>

  </tr><?php } else { } ;?>

</table>

The field 'frontpage'  in the database is set to ENUM with 'y','n' as the possible options. Ideally what I'm trying to do is get this working so that if the listing has 'n' it doesn't show in this table, if it has a 'y' it does, but when I test it locally it either serves up the first listing in the table (there are only two for test purposes) or shows nothing if I change the value from "n". I'd appreciate some guidance on how to get this to work. Thanks in advance.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines