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

Reply

Join Date: Jan 2009
Posts: 5
Reputation: guitarscn is an unknown quantity at this point 
Solved Threads: 0
guitarscn guitarscn is offline Offline
Newbie Poster

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

 
0
  #1
Jan 9th, 2009
I have a .php web page with these lines:

  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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,010
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 130
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster

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

 
0
  #2
Jan 9th, 2009
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:
  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:

  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:

  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:

  1. <p>My magic number is <?=addslashes(htmlentities($_GET['v']));?></p>
Last edited by ardav; Jan 9th, 2009 at 7:25 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC