homepage Welcome to WebmasterWorld Guest from 54.166.65.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Delete thing if no value
tr8er8




msg:3576268
 10:44 pm on Feb 15, 2008 (gmt 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?

 

IanKelley




msg:3576315
 11:25 pm on Feb 15, 2008 (gmt 0)

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.

tr8er8




msg:3576374
 12:47 am on Feb 16, 2008 (gmt 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.

IanKelley




msg:3576406
 2:00 am on Feb 16, 2008 (gmt 0)

Ah, ok... Well in that case it should be pretty simple, can you post a code snippet?

tr8er8




msg:3576459
 4:08 am on Feb 16, 2008 (gmt 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.

IanKelley




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

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.

tr8er8




msg:3576501
 6:05 am on Feb 16, 2008 (gmt 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?

IanKelley




msg:3576506
 6:27 am on Feb 16, 2008 (gmt 0)

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

Right.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved