Page 1 of 1

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

Posted: Mon Mar 08, 2004 7:34 am
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 '>';
}
?>

Posted: Mon Mar 08, 2004 8:21 am
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.'"';
?>

Posted: Tue Mar 09, 2004 1:36 pm
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.
?>