Jump to content

show region if column is not empty


emediastudios

Recommended Posts

I want to be able to show region if recordset, column,  is not empty.

 

This is the code in my php file.

<a href="images/<?php echo $_POST['photo3']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo3']; ?>" alt="image" width="150" border="0" />

 

How would i alter this code if i wanted to only show this image (region) it if there was a record in database (gcproperty) column (photo3)

Thanks a heap

;)

Link to comment
Share on other sites

i did as you mentioned and it now refuses to show the image wether there is a record or not.

 

This is what i did

 

<a href="images/<?php echo $_POST['photo3']; ?>" target="_blank"></a><a href="images/<?php echo $_POST['photo2']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo2']; ?>" alt="image" width="150" border="0" /></a>
  
            

 

Changed to

 

<?php

if (!empty($db_var)){
?>
<a href="images/<?php echo $_POST['photo3']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo3']; ?>" alt="image" width="150" border="0" /></a>

<?php } ?>

Link to comment
Share on other sites

I put the variable $db_var in there, so you could replace it with your database variable.

 

<?php

//connect to your database

$query = "SELECT photo3 FROM employees WHERE (put condition here)";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);

if (!empty($row['photo3'])){
?>

<a href="images/<?php echo $_POST['photo3']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo3']; ?>" alt="image" width="150" border="0" /></a>

<?php } ?>

?>

 

I'm not exactly sure what you are trying to do. If what I just did isn't what you want, then explain a little more.

Link to comment
Share on other sites

Thanks pocobueno1388.

The code you have is what i need im sure.

I'm new to php and have been teaching myself from google searches and from these forums 4 around 6 months now.

sorry if i sound stupid or you find it hard to understand what im trying to do, i am having difficulty explaining and i cant blame you  :)

Will try your code and get back to you.

Just one more question, what would i put in (put condition here).

I try to explain what i want to do.

I have a page that shows all records. That page displays some information on every record, but hides the bulk of the records info in hidden fields.

I then made form varibles in dreamweaver, named to match the fields in my database.

when the user presses the view more button it posts all the form varibles onto my show all details page.

My show all details page has (9) dynamic image fields that are populated from the form varibles from the previous file.

Problem is not all my properties have (9) images and i wish to hide that region if there is no data posted to that dynamic image field.

Does this make sense?

 

 

Link to comment
Share on other sites

Correct me if im wrong but could there be a code that checks if the posted form varible had data and display region if true,

and hide region if the posted form varible had no data.

 

This is my first file

 

<?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?>
    <form action="full_details.php" method="post" enctype="multipart/form-data" name="properties" target="_self" id="properties">
      <table width="600" align="center" bgcolor="#F1F1F1">
      <tr>
        <td width="437" align="left" valign="top" bordercolor="#000000" bgcolor="#FFFFFF"><span class="style1"><u><?php echo $row_Recordset1['name']; ?></u></span><span class="style3">
        <label>
        <input name="name" type="hidden" id="name" value="<?php echo $row_Recordset1['name']; ?>" />
        </label>
        <label></label>
        </span> <span class="style3"><br />
          <span class="style5"><?php echo $row_Recordset1['price']; ?>
          <label></label>
          <label>
          <input name="price" type="hidden" id="price" value="<?php echo $row_Recordset1['price']; ?>" />
          </label>
          <br />
          <?php echo $row_Recordset1['suburb']; ?>
          <label></label>
          <label>
          <input name="suburb" type="hidden" id="suburb" value="<?php echo $row_Recordset1['suburb']; ?>" />
          </label>
          <br />
          </span></span><span class="style3"><?php echo $row_Recordset1['content']; ?>
          <label>
          <input name="content" type="hidden" id="content" value="<?php echo $row_Recordset1['content']; ?>" />
          <input name="content2" type="hidden" id="content" value="<?php echo $row_Recordset1['content2']; ?>" /><br />
<input name="photo" type="hidden" id="photo" value="<?php echo $row_Recordset1['photo']; ?>" />
          <br />
<input name="photo2" type="hidden" id="photo2" value="<?php echo $row_Recordset1['photo2']; ?>" />
          <br />
</label>
          

          <label>
          <input name="photo3" type="hidden" id="photo3" value="<?php echo $row_Recordset1['photo3']; ?>" />
          </label>
          <label>
          <input name="photo4" type="hidden" id="photo4" value="<?php echo $row_Recordset1['photo4']; ?>" />
          </label>
          <label>
          <input name="photo5" type="hidden" id="photo5" value="<?php echo $row_Recordset1['photo5']; ?>" />
          </label>
          <label>
          <input name="photo6" type="hidden" id="photo6" value="<?php echo $row_Recordset1['photo6']; ?>" />
          </label>
          </span>
          <label>
          <input name="photo7" type="hidden" id="photo7" value="<?php echo $row_Recordset1['photo7']; ?>" />
          <input name="photo8" type="hidden" id="photo8" value="<?php echo $row_Recordset1['photo8']; ?>" />
          <input name="photo9" type="hidden" id="photo9" value="<?php echo $row_Recordset1['photo9']; ?>" />
          </label></td>
        <td width="151"><div align="center"><a href="images/<?php echo $row_Recordset1['photo']; ?>" target="_blank"><img src="images/<?php echo $row_Recordset1['photo']; ?>" alt="image" width="150" border="0" /></a></div></td>
      </tr>
      
      
      <tr>
        <td colspan="2"></td>
      </tr>
      
      <tr>
        <td height="23" colspan="2" bgcolor="#666666"><a href="full_details.php" target="_self">
          <label>
          <input type="submit" name="submit" id="submit" value="more info" />
          </label>
        </a></td>
      </tr>
    </table>
    </form>

 

This is my second file that shows the full details

 

<form action="show2.php" method="get" enctype="application/x-www-form-urlencoded" name="fav" target="_self" id="fav">
  <br />
  <table width="640" border="0" align="center">
    <tr>
      <td width="101"> </td>
      <td width="41"> </td>
      <td width="350"> </td>
      <td width="40"><div align="left"><script type="text/javascript" src="favlink.js">
</script>
</div></td>
      <td width="40"><div align="left"><a href="javascript:window.print()"><img src="images/print.png" alt="print this page" border="0" /></a> </div></td>
      <td width="42"><div align="left"><a href="sendpage.php" target="_self"><img src="images/send.png" alt="send to friend" width="16" height="16" border="0" /></a></div></td>
    </tr>
  </table>
  <table width="645" align="center">
    <tr>
      <td colspan="2" align="left" valign="top" bordercolor="#000000" bgcolor="#F1F1F1"><div align="left"><span class="style1"><u> <?php echo $_POST['name']; ?></u></span> </div>
      <div align="right"></div></td>
    </tr>
    <tr>
      <td width="173" align="left" valign="top" bordercolor="#000000" bgcolor="#FFFFFF"><table width="156" border="0">
          <tr>
            <td width="150" height="403" valign="top">
           <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo2']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo2']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

              <br />
          <table width="150" border="0">
  <tr>
   <td><a href="images/<?php echo $_POST['photo3']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo3']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
           <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo4']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo4']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>
<br />

            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo5']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo5']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo6']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo6']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo7']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo7']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
            <table width="150" border="0">
  <tr>
    <td><a href="images/<?php echo $_POST['photo8']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo8']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>

            <br />
           <table width="150" border="0">
  <tr>
    <td> <a href="images/<?php echo $_POST['photo9']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo9']; ?>" alt="image" width="150" border="0" /></a><br /></td>
  </tr>
</table>
</td>
          </tr>
        </table>
       </td>
      <td width="460" valign="top"><table width="200" border="0">
          <tr>
            <td><a href="images/<?php echo $_POST['photo']; ?>" target="_blank"><img src="images/<?php echo $_POST['photo']; ?>" alt="image" width="450" border="0" /></a></td>
          </tr>
      </table>
      <br />
      <table width="459" border="0">
        <tr>
          <td bgcolor="#F1F1F1"><span class="style5"><?php echo $_POST['price']; ?></span></td>
          </tr>
        <tr>
          <td><span class="style5"><?php echo $_POST['suburb']; ?></span></td>
          </tr>
        <tr>
          <td height="270" valign="top"><span class="style3"><?php echo $_POST['content']; ?><br />
            <hr width="300" />
          </span><span class="style3"><?php echo $_POST['content2']; ?></span></td>
          </tr>
      </table>
      <div align="right"></div></td>
    </tr>
    <tr>
      <td colspan="2" align="left" valign="top" bordercolor="#000000" bgcolor="#F1F1F1"> </td>
    </tr>
    
    
    <tr>
      <td colspan="2"></td>
    </tr>
  </table>
</form>

 

Hope this helps

 

Thanks for your help, thought this would be a simple fix but have been on it for a week and i am tearing my hair out over it. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.