The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
So I am trying to pass some php into html to make the coding more compact. I have a form that is filled out in the HTML page that includes the PHP, which is then parsed to another PHP page for evaluation. Esstentially I am trying make a drop down list of 100 selection in a few lines of code. Here is what I have so far but I am not sure if it is any good, I haven't found any good resources on embedding PHP in a mainly HTML form. I guess a better question: is this possible?
<?php
echo ('Select an interger');
echo ('<select name=\"interger\">');
for ($n=0; $n=<100; $n++) {
echo ('<option value=\"$n\">$n</option>');
}
echo ('</select>');
?>
Seguerof the VoidSydney, AustraliaRegistered Userregular
edited June 2007
That should work, but will give you 0 - 100.
Also, integer, not interger.
As to "embedding PHP within HTML" - this specific thing is impossible, as PHP runs on server-side and HTML is parsed client-side. PHP can output HTML, but you will never see working PHP code in the View Source of a HTML page
As to "embedding PHP within HTML" - this specific thing is impossible, as PHP runs on server-side and HTML is parsed client-side. PHP can output HTML, but you will never see working PHP code in the View Source of a HTML page
Thats what I was thinking, someone tried to convince me otherwise but I think they were getting confused with Javascript.
Eh, thats just me writing an example on the fly as I am talking w/ my GF on the phone.
For some reason, I am using IIS and htt://localhost/... to test my script but I am not getting any error codes in response, just blank pages or section of the codes.
For some reason, I am using IIS and htt://localhost/... to test my script but I am not getting any error codes in response, just blank pages or section of the codes.
I don't know IIS but if it was Apache that sound like the file extension options haven't been set right ad the sever is trying to treat the files as plain html without processing the PHP. What's the file extension of the files you are testing? If they are .htm/.html then that might well be the reason. Try changing the extensions to .php to see if that makes a difference or fiddling around with IIS to alter the file associations.
Seguerof the VoidSydney, AustraliaRegistered Userregular
edited June 2007
Are you seeing your PHP code in those blank pages/sections of code? Then Alistair is correct - PHP isn't being told to parse the page, thus PHP won't do anything there. Easiest way is to make a new PHP file ("phpinfo.php") with the following contents:
Yeah, that's possible, and would probably work as written. However, I suggest using a template engine such as Smarty rather than mixing PHP and HTML.
Agreeing with this.
Smarty makes everything so much simpler. We used it at my old work to power 10+ sites, and the templates we used were so easy to read because of Smarty..
The separation of data / logic from presentation is something that you should already be doing in your XHTML / CSS - so taking it a step further and doing it with your PHP is the next logical progression.
Of course, for something that's probably one form I wouldn't bother - but for mulitple scripts it's a Godsend.
Smarty.
SporkAndrew on
The one about the fucking space hairdresser and the cowboy. He's got a tinfoil pal and a pedal bin
Posts
Also, integer, not interger.
As to "embedding PHP within HTML" - this specific thing is impossible, as PHP runs on server-side and HTML is parsed client-side. PHP can output HTML, but you will never see working PHP code in the View Source of a HTML page
Thats what I was thinking, someone tried to convince me otherwise but I think they were getting confused with Javascript.
Eh, thats just me writing an example on the fly as I am talking w/ my GF on the phone.
For some reason, I am using IIS and htt://localhost/... to test my script but I am not getting any error codes in response, just blank pages or section of the codes.
I don't know IIS but if it was Apache that sound like the file extension options haven't been set right ad the sever is trying to treat the files as plain html without processing the PHP. What's the file extension of the files you are testing? If they are .htm/.html then that might well be the reason. Try changing the extensions to .php to see if that makes a difference or fiddling around with IIS to alter the file associations.
I made a game, it has penguins in it. It's pay what you like on Gumroad.
Currently Ebaying Nothing at all but I might do in the future.
and run it.
Agreeing with this.
Smarty makes everything so much simpler. We used it at my old work to power 10+ sites, and the templates we used were so easy to read because of Smarty..
Instead of doing silly things like:
You'd just do:
The separation of data / logic from presentation is something that you should already be doing in your XHTML / CSS - so taking it a step further and doing it with your PHP is the next logical progression.
Of course, for something that's probably one form I wouldn't bother - but for mulitple scripts it's a Godsend.
Smarty.