LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-09-2009, 04:12 PM   #1
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Rep: Reputation: 30
How do I output information from a PHP page to an HTML page?


I have a .php web page with these lines:

Code:
//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?
 
Old 01-09-2009, 04:46 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
You can have php modify the html file.

You can create a link to the html file with GET vars in the link, then have something like javascript in the html file display the GET vars.

Is there a reason that html file needs to be an html file? This may be a lot easier if it were a php file. You know, you can simply rename a .html file to a .php file & it will display the same.... then you can write php code iside of a php tag in the file & it will work the way you may expect.
 
Old 01-09-2009, 08:51 PM   #3
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
if it does need to be a .html file (for whatever reason, such as SEO [.html file is better than xyz.php?a=b&c=d&e=f etc...] ) but want to insert .php in there, then either

a) enable mod_rewrite and tweak around
or
b) add .html to this line in your apache configuration "AddType application/x-httpd-php .php .phtml .php3"

while b) is faster / simpler, a) in the end is cleaner, and also has other benefits
 
Old 01-10-2009, 01:54 AM   #4
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

The whole point of PHP is that it lets you modify your HTML before you send it to the server!

Suggestion: name *all* the pages on your site ".php". Even if they're pure HTML. For example:
Code:
<html>
<head>
  <title>Hello world</title>
</head>
<body>
Hello World
</body>
</html>
  <= Create this page as "hello.php"
Then, in your scenario, you can modify it like this:
Code:
<html>
<head>
  <title>Hello world</title>
</head>
<body>
Hello World
<?php
  //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);

  // Display results
  if ($commentNum == 0) {  
    echo "<p>There were no comments</p>";
  }
  else {
    echo "<p>There were $CommentNum comments</p>";
 ?>
</body>
</html>
'Hope that helps .. PSM

PS:
Please consider the suggestion about looking at bulletin board software I made in the previous post. But I'm glad your looking at mySQL to store your comments, and it looks like you're making great progress!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP include upsets rendering of HTML page. rblampain Programming 6 01-19-2013 04:50 AM
PHP - incremental/partial output of a page ? michaelsanford Programming 1 07-13-2005 12:37 AM
php function to open an html page prabhatsoni Linux - Software 2 06-13-2005 11:32 PM
RH & HP4050N PCL - page, pause, page, pause, page andguent Linux - Hardware 0 11-10-2003 08:35 AM
Creating a simple html page from php? lucastic Linux - General 4 11-05-2003 08:48 AM


All times are GMT -5. The time now is 01:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration