468,252 Members | 1,468 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,252 developers. It's quick & easy.

html within php works, but php within html doesnt

Below are two different ways of writing the same script. The top one works
but the bottom one displays nothing in the list. Can anyone see why?

<?php
echo "<select name='subcat' style='WIDTH: 95%'><option value=''>Select
one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[TopicID]'>$noticia[Topic]</option>";
}
echo "</select>";
?>

<select name="subcat" style="WIDTH: 95%">
<option value="">Select one</option>
<?php while($noticia = mysql_fetch_array($quer)) { ?>
<option value="<?php $noticia[TopicID]; ?>"><?php $noticia[Topic];
?></option>
<?php } ?>
</select>

Ian
Sep 2 '06 #1
4 3126
On Sat, 02 Sep 2006 13:19:38 GMT, "mantrid" <ia********@virgin.netwrote:
><option value="<?php $noticia[TopicID]; ?>"><?php $noticia[Topic];
?></option>
You haven't done anything in those PHP blocks; you need "print" or "echo".

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 2 '06 #2
DOOH!
Knew it was somethin simple
Cheers

"Andy Hassall" <an**@andyh.co.ukwrote in message
news:gh********************************@4ax.com...
On Sat, 02 Sep 2006 13:19:38 GMT, "mantrid" <ia********@virgin.netwrote:
<option value="<?php $noticia[TopicID]; ?>"><?php $noticia[Topic];
?></option>

You haven't done anything in those PHP blocks; you need "print" or
"echo".
>
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Sep 2 '06 #3

mantrid wrote:
Below are two different ways of writing the same script. The top one works
but the bottom one displays nothing in the list. Can anyone see why?

<?php
echo "<select name='subcat' style='WIDTH: 95%'><option value=''>Select
one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[TopicID]'>$noticia[Topic]</option>";
}
echo "</select>";
?>

<select name="subcat" style="WIDTH: 95%">
<option value="">Select one</option>
<?php while($noticia = mysql_fetch_array($quer)) { ?>
<option value="<?php $noticia[TopicID]; ?>"><?php $noticia[Topic];
?></option>
<?php } ?>
</select>

Ian
Because you're not actually doing anything with that code. HTML isn't a
templating language, you can't just plug values in surrounded by php
tags. you have to actually *do* something with the values. Replace the
4th line with this:

<option value="<?php echo $noticia[TopicID]; ?>"><?php echo
$noticia[Topic]; ?></option>

Cheers,
Paul

Sep 2 '06 #4
mantrid wrote, On 3/09/06 1.19 a:
echo "<option value='$noticia[TopicID]'>$noticia[Topic]</option>";
The problem is in the way that you reference the $noticia array. In your
first example, you a double-quoted string, this causes PHP to
automatically grab the value from the array, but in your second example...
<option value="<?php $noticia[TopicID]; ?>"><?php $noticia[Topic];
You don't. You'll need to give it the key of the array as a string, like
$noticia['TopicID']

When using double-quoted strings, something like "$array[key]" will grab
the variable $array['key'], unless you use curly-braces like
"{$array['key']}".

See:
<http://nz.php.net/manual/en/language.types.string.php#language.types.string.pa rsing.simple>

-Phil
Sep 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Hank | last post: by
9 posts views Thread by T.Michelle | last post: by
2 posts views Thread by Lei Wu | last post: by
4 posts views Thread by Arthur Dent | last post: by
2 posts views Thread by EagerToKnow | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.