Re: Reg. Dynamically populate a checkbox
- From: mootmail-googlegroups@xxxxxxxxx
- Date: 29 Aug 2006 08:40:21 -0700
Dennis de Wit wrote:
mootmail-googlegroups@xxxxxxxxx wrote:
Mumia W. wrote:
Within an echo statement, <? php-code ?> does not work. Just
output a variable's value:
$event_publish_checked = ($event_publish == 1 ? 'CHECKED' : '');
echo "<tr>
<td Class='navText' align='center' class=$c>$event_id</td>
<td class='navText' class=$c>$event_name</td>
<td class='navText' align='center' class=$c><INPUT TYPE=CHECKBOX
NAME='publish' VALUE=1 $event_publish_checked </td>
<td class='navText' align='center' class=$c><a
href='delete_event.php?event_id=$event_id'>$take_action</a></td></tr>";
Alternatively, instead of setting a variable, you can just return the
result of the ternary operator as follows:
<?=($event_publish == 1 ? 'CHECKED' : '')?>
Note the '=' rather than 'echo'.
I think someone just noted that you cannot use the <? ?> markers in an
ECHO statement. Knowing that, this example is, sorry if I bring this
quite rudely, useless.
Ah, yes. I admit that I only skimmed the post and failed to notice
that the entire HTML segment was, itself, being output from an echo
statement. I had assumed that the snippet was in html mode, and could
drop into php mode legally. You are correct in my example being
invalid. If, however, the OP were to drop out of php mode to output
the html rather than using echo, it would be valid.
Besides, I think it's not smart to teach this method to someone who just
started using PHP. Using plain style 'if' statements is a way better
method to start learning how to program.
So again, I think the OP should close the echo statement, start a new
line, place the IF statement there, and then continue echo-ing whatever
he wants. The ternary operator (i didn't know they call them that way)
is something a starting programmer should learn if the time is right. I
don't think that's now for OP.
I will, however, defend my suggestion of the ternary operator, if only
because the OP him/her self used it in their second post. So either
they already know it, or they copied it from somewhere else. And if
they copied code from somewhere, I would hope that they at least took a
moment to understand what it does, first.
.
- References:
- Reg. Dynamically populate a checkbox
- From: calms
- Re: Reg. Dynamically populate a checkbox
- From: Mumia W.
- Re: Reg. Dynamically populate a checkbox
- From: calms
- Re: Reg. Dynamically populate a checkbox
- From: Mumia W.
- Re: Reg. Dynamically populate a checkbox
- From: mootmail-googlegroups
- Re: Reg. Dynamically populate a checkbox
- From: Dennis de Wit
- Reg. Dynamically populate a checkbox
- Prev by Date: Re: Reg. Dynamically populate a checkbox
- Next by Date: Archiving External Sites
- Previous by thread: Re: Reg. Dynamically populate a checkbox
- Next by thread: Archiving External Sites
- Index(es):
Relevant Pages
|