Welcome to WebmasterWorld Guest from 23.22.220.37

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Delete thing if no value

     
10:44 pm on Feb 15, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2008
posts: 94
votes: 0


Hi I have a script thingy that where you type in a url to an image, and a caption for the image that will go into articles. It works fine and all, but when you dont put in a URL to an image or a caption its just a gray box with a border. I want it so if the values in the text boxes are empty, then the image borders and all doesn't show up. Do you have any clue how I would do this?
11:25 pm on Feb 15, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts: 1259
votes: 11


With the information you posted it's hard to answer your question.

Going by what I can infer though, you're getting a bit ahead of yourself. :-)

Without a basic knowledge of PHP the kinds of modifications you want to make are impossible.

However after a few days practice getting to know the language you would be able to do it easily. Lots of great books and tutorials available out there.

12:47 am on Feb 16, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2008
posts: 94
votes: 0


Nah its not that I'm a beginner, I know pretty much most of the basics, and how to get stuff through datbases and mysql and stuff, but I'm just not familiar with how to cancel a function or something if a value in a textbox is empty.
2:00 am on Feb 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts: 1259
votes: 11


Ah, ok... Well in that case it should be pretty simple, can you post a code snippet?
4:08 am on Feb 16, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2008
posts:94
votes: 0


The part that is displaying it is:

<p><div class="imgBox"><img src="<?php print $post_image; ?>" /><div class="captionBox"><?php print $post_imageCap; ?></div></div><?php print $post_content; ?></p>

The other part is just putting the URL into the table, then its just taking it out. Its mixed with all the other stuff in the articles like the date, author, title, content, etc.

4:35 am on Feb 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts: 1259
votes: 11


Well the most straightforward way to do it would be to break the HTML output up in to if statements, something like...


print '<p>';
if ($post_image != '') {
?>
<div class="imgBox"><img src="<?php print $post_image; ?>" />
<div class="captionBox"><?php print $post_imageCap; ?></div></div>
<?
}
print $post_content.'</p>';

But it might also make sense to put the condition in with the input validation, just depends on how the existing script is written.

6:05 am on Feb 16, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Feb 6, 2008
posts:94
votes: 0


Wow thanks that worked perfect, didnt even make a change to that script. Could you explain how it works, becuase all I see if I'm corrent is if $post_image is empty, it displays the html. Or no, its probably if it has a value, it displays that, otherwise it displays nothing?
6:27 am on Feb 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts: 1259
votes: 11


, its probably if it has a value, it displays that, otherwise it displays nothing?

Right.