emediastudios Posted September 29, 2007 Share Posted September 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/ Share on other sites More sharing options...
pocobueno1388 Posted September 29, 2007 Share Posted September 29, 2007 <?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" /> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/#findComment-357661 Share on other sites More sharing options...
emediastudios Posted September 29, 2007 Author Share Posted September 29, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/#findComment-357676 Share on other sites More sharing options...
emediastudios Posted September 29, 2007 Author Share Posted September 29, 2007 The table within the gcproperty database is called employees. If thats any help. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/#findComment-357677 Share on other sites More sharing options...
pocobueno1388 Posted September 29, 2007 Share Posted September 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/#findComment-357880 Share on other sites More sharing options...
emediastudios Posted September 29, 2007 Author Share Posted September 29, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/#findComment-358106 Share on other sites More sharing options...
emediastudios Posted September 29, 2007 Author Share Posted September 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71119-show-region-if-column-is-not-empty/#findComment-358111 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.