472,780 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

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 3252
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
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
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
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
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
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
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
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
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
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.