943,920 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 661
  • PHP RSS
Jan 9th, 2009
0

How do I output information from a PHP page to an HTML page?

Expand Post »
I have a .php web page with these lines:

PHP Syntax (Toggle Plain Text)
  1. //gather all the comments
  2. $commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date DESC") or die(mysql_error());
  3.  
  4. //count all the comments for the total
  5. $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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guitarscn is offline Offline
5 posts
since Jan 2009
Jan 9th, 2009
0

Re: How do I output information from a PHP page to an HTML page?

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:
PHP Syntax (Toggle Plain Text)
  1. RemoveHandler .html .htm
  2. 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)
  1. 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)
  1. <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)
  1. <p>My magic number is <?=addslashes(htmlentities($_GET['v']));?></p>
Last edited by ardav; Jan 9th, 2009 at 7:25 pm.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 948
Sarcastic Poster
ardav is offline Offline
6,698 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Page is not showing up at all - Help me rectify the error.
Next Thread in PHP Forum Timeline: separate query result in different columns





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC