473,586 Members | 2,633 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_arr ay($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_arr ay($quer)) { ?>
<option value="<?php $noticia[TopicID]; ?>"><?php $noticia[Topic];
?></option>
<?php } ?>
</select>

Ian
Sep 2 '06 #1
4 3275
On Sat, 02 Sep 2006 13:19:38 GMT, "mantrid" <ia********@vir gin.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.u k :: 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.c om...
On Sat, 02 Sep 2006 13:19:38 GMT, "mantrid" <ia********@vir gin.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.u k :: 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_arr ay($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_arr ay($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#lang uage.types.stri ng.parsing.simp le>

-Phil
Sep 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1436
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 way to upload all his files to his personal folder in the virtual directory and have a html page that basically shows all the recent uploaded files...
2
2440
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 XML file will get their row content from there. The rows may look some thing similar to this: - Added <a>mailing list</a> functionality to...
9
1515
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. I am not able to get this. I tried with
2
1010
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 return between the <img> tag and the </td> tag. I thought hard returns don't make a differnt unless in <pre> tags, but apparently I was wrong.
4
1591
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 tables to layout my pages, doing three rows, a header, content and footer. When i do this, i make the tables height=100%, so the footer always shows...
3
3795
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 access the the tags and tags value (<td> <table>, etc) by code. But it just doesn't work in VB.NET but works in VB6. Please someone just show me...
2
1316
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. The linkHandler.html is : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
10
3449
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 ------------- I have perl script which simply runs a ps on a Solaris server and generates a static html page with all of the code perfectly and this html page...
1
2161
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 http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.