Re: Reg. Dynamically populate a checkbox
- From: Dennis de Wit <newsgroups@xxxxxxxxxxxxxxx>
- Date: Tue, 29 Aug 2006 14:26:10 +0200
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.
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.
Dennis
(OP = Original Poster)
.
- Follow-Ups:
- Re: Reg. Dynamically populate a checkbox
- From: mootmail-googlegroups
- Re: Reg. Dynamically populate a checkbox
- 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
- Reg. Dynamically populate a checkbox
- Prev by Date: Re: Reg. Dynamically populate a checkbox
- Next by Date: Re: Reg. Dynamically populate a checkbox
- Previous by thread: Re: Reg. Dynamically populate a checkbox
- Next by thread: Re: Reg. Dynamically populate a checkbox
- Index(es):