display the number: 0 in a textbox with php for editing

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
parkin
Forum Commoner
Posts: 25
Joined: Wed Jul 23, 2003 3:18 am

display the number: 0 in a textbox with php for editing

Post by parkin »

Hi..

I've got a slight bug in my codes.. What I would like to do is:

1) retrieve from database (basically I stored numbers -- 0 and 1, 2 etc for an adminstatus)
2) display it in the textbox for editing..

I've managed to do both.. But if the number retrieved from the database is a 0, it will not be displayed in my textbox, it displays other numbers except 0. :?

Does anyone know why? or have any ideas to get around it?
Really apprieciate any help given.. :D

Here's how I did it:

Code: Select all

<?php
// textbox in the form
html_text("form[accessLevel]",$row[accessLevel],'','',"formEle"); 


// function to display the textbox
function html_text($name, $value='', $size='', $maxlength='', $class='')
{
	print '<input type="text" name="'.$name.'"';
	if($value){print ' value="'.$value.'"';}
	if($size){print ' size="'.$size.'"';}
	if($maxlength){print ' maxlength="'.$maxlength.'"';}
	if($class){print ' class="'.$class.'"';}
	print '>';
}
?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

i think that an zero is classed as empty

Code: Select all

<?php
   if($value){print ' value="'.$value.'"';} 
?>
i think you need to change that if statement;

Code: Select all

<?php
   print ' value="'.$value.'"';
?>
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Correct. 0 will return as "no value" and this if ($variable) will never return true. I believe this would also work:

їphp]
if ($value || $value == "0")
ї/php]

but I'm not entirely sure about that.
?>
Post Reply