<?php do Confusion

I currently have a php database set up so that when you open up the page that it shows up on. If the database has something inside of it than it will show the information if not than it will display a “Sorry currently no files available type of thing”

For example:

<?php do { ?>
<?php echo $row_rsHOUSES['mainImage']; ?>

<?php echo $row_rsRENTALS['houseName']; ?>

<?php echo $row_rsRENTALS['price']; ?>
<?php } while ($row_rsRENTALS = mysql_fetch_assoc($rsRENTALS)); ?> <?php if ($totalRows_rsRENTALS == 0) { // Show if recordset empty ?> ---------- No Rental Properties Available ----------

Even though we currently don't have property up for sale. Feel free to contact us to look into designing your very own custom Pre-Sold today. We are committed to supporting you throughout the home building process and through every stage from construction to completion.

We are commited to your comfort.
This is not only our policy is our philosophy. Its the way we do business.

                  <?php } // Show if recordset empty ?>
            </table></blockquote>

The problem I’m running into. Is that I have an image inside of that <?php do statement. When the database is blank everything is removed except for the box that the image would of gone inside of. Is there anyway to make the image box vanish as well when the database is empty?

Nevermind :slight_smile: Resolved the problem. Decided to move the link inside of the database instead of on the main page allowing for the image to vanish and reappear as necessary.

Thanks Anyways!

Hi,

Glad you fixed it…

As an alternate, bear this in mind…
when a do/while is encountered the loop is always executed at least once.
therefore when it runs through this initial loop and the database is empty then it will not show anything, except maybe an empty image…

Now, if you used a while loop (not do/while) and your database is empty then the loop will not be executed and you won’t get unwanted results like empty images etc…

Hope this helps
:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service