473,508 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3270
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1432
by: Hank | last post by:
A friend of mine recently asked me to help him. Basically he has a virtual directory on his companies webserver with his files and other stuff that he downloads all the time. What he wanted was a...
2
2435
by: bissatch | last post by:
Hi, I am currently writing a simple PHP program that uses an XML file to output rows for a 'Whats New' page. Once written, I will only require updating the XML file and any pages that use the...
9
1512
by: T.Michelle | last post by:
We have few Mail templates (.html) which we use to send mails. We want to have some Logo in that ie ... when I send the mail to user the image should go as in-line embedded image in mail....
2
1006
by: Lei Wu | last post by:
Hi, guys, As an Internet developer for many years, I thought I knew HTML... until I came across this: The following two tables look different in IE 6.0. I've pinpointed the cause -- the hard...
4
1584
by: Arthur Dent | last post by:
Hello all, ive been programming with ASP.NET since it came out, but am just getting my feet with now with v.2. Ive noticed something strange in the way my HTML tables get rendered with 2. I use...
3
3784
by: Joe | last post by:
Hi, I have a simple thing I need to do but just doesn't work in VB.NET. I have a string with HTML code and I want to load it into a HTMLDocument object or something similiar to it so I can...
2
1309
by: EagerToKnow | last post by:
I am trying to have it cleaner. I have two files : 1) linkHandler.html 2)linkHandler.js I am trying to call a function that is there in js file from within html file for an 'onClick' event. ...
10
3427
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
1
2139
by: reemamg | last post by:
Have a piece of code which works in Firefox however doesnt work in IE <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.