I have a .php web page with these lines:

//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?

8 Years
Discussion Span
Last Post by diafol

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:

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:


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:

<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:

<p>My magic number is <?=addslashes(htmlentities($_GET['v']));?></p>
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.