| | |
How do I output information from a PHP page to an HTML page?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
Posts: 5
Reputation:
Solved Threads: 0
I have a .php web page with these lines:
I want the value of $commentNum which is going to be a number, to be displayed on another page that's written in HTML (.html extension) from the .php page.
How can I transfer this number over?
PHP Syntax (Toggle Plain Text)
//gather all the comments $commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date DESC") or die(mysql_error()); //count all the comments for the total $commentNum = mysql_num_rows($commentquery);
I want the value of $commentNum which is going to be a number, to be displayed on another page that's written in HTML (.html extension) from the .php page.
How can I transfer this number over?
If you can create an .htaccess file to your webroot - no problem.
Your webroot will look something like this: /home/usr/public_html
Search for an .htaccess file. If it doesn't exist you can create one in a text editor like Notepad. Save it as htacccess.txt.
Put this code into the file:
Save and close the file. FTP it to your webroot directory. Rename the file .htaccess (that's period followed by htaccess). If you try to upload the file already called .htaccess, it won't work.
You can now include php tags in your html file just as if it had a .php extension.
I used this no problem and got the original info from http://www.desilva.biz/php/phpinhtml.html
If you want to pass this from a php page to your html instead of just embedding the php code in your html page you can do something like this:
In your php page following the retrieval of your variable:
This will work as long as no text is displayed (echoed) on the php prior to the html call.
You can then retrieve the $var number from a simple $_GET variable. In your html page:
However, I would strongly suggest that you clean the $_GET variable or you could kill the page; do something like:
Your webroot will look something like this: /home/usr/public_html
Search for an .htaccess file. If it doesn't exist you can create one in a text editor like Notepad. Save it as htacccess.txt.
Put this code into the file:
PHP Syntax (Toggle Plain Text)
RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html
Save and close the file. FTP it to your webroot directory. Rename the file .htaccess (that's period followed by htaccess). If you try to upload the file already called .htaccess, it won't work.
You can now include php tags in your html file just as if it had a .php extension.
I used this no problem and got the original info from http://www.desilva.biz/php/phpinhtml.html
If you want to pass this from a php page to your html instead of just embedding the php code in your html page you can do something like this:
In your php page following the retrieval of your variable:
PHP Syntax (Toggle Plain Text)
header("Location:myhtmlpage.html?v={$var}");
This will work as long as no text is displayed (echoed) on the php prior to the html call.
You can then retrieve the $var number from a simple $_GET variable. In your html page:
PHP Syntax (Toggle Plain Text)
<p>My magic number is <?=$_GET['v'];?></p>
However, I would strongly suggest that you clean the $_GET variable or you could kill the page; do something like:
PHP Syntax (Toggle Plain Text)
<p>My magic number is <?=addslashes(htmlentities($_GET['v']));?></p>
Last edited by ardav; Jan 9th, 2009 at 7:25 pm.
![]() |
Similar Threads
- Compile PHP (PHP)
- error in my login page (PHP)
- PHP Text-Area Help (PHP)
- PHP, MySQL and HTML help (PHP)
- Pass a javascript variable to PHP in the same function (JavaScript / DHTML / AJAX)
- View HTML source in php page? (PHP)
- PHP Help - Display forum online and total members on main page (PHP)
- Script stores data in wrong MySQL columns (MySQL)
- Apache mod_rewrite with Google Ads (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: Page is not showing up at all - Help me rectify the error.
- Next Thread: separate query result in different columns
| Thread Tools | Search this Thread |
ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl database date delete display dynamic echo email error external file files filter folder form forms function functions gc_maxlifetime google host href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php problem query question radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube






