hOW CAN WE CREATE DYNAMIC HTML PAGE IN PHP ON EVERY CLICK

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
abhardwaj847
Forum Newbie
Posts: 2
Joined: Mon Jul 26, 2010 3:42 am

hOW CAN WE CREATE DYNAMIC HTML PAGE IN PHP ON EVERY CLICK

Post by abhardwaj847 »

HI

i have a big problem, we are developing a site like this http://www.consumercomplaints.in/, all the pages are html pages in this site, we also want to do same in php,

when we submit any complaint then with the title of complaint a html page should be generate.

plz. help.

thanks
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: hOW CAN WE CREATE DYNAMIC HTML PAGE IN PHP ON EVERY CLIC

Post by MindOverBody »

Let's assume that you have database, and it's called "complaints".
Now, assume that database have table called "comp_table", and table have three columns called "id", "title" and "content".
I'll also assume that you know how to connect to database, and you are already connected.

This script will get all complaints whit newest on top and will make links, so when link is clicked it will get complaint title and content.

Code: Select all

$Result = mysql_query("SELECT id, title FROM complaints ORDER BY id DESC");
if ( mysql_num_rows( $Result ) > 0 ) {
      while ( $Data = mysql_fethc_array( $Result ) ) {
            echo "<a href='?c=" . $Data["id"] . "'>" . $Data["title"] . "</a><br />";
      }
}

if ( isset($_GET["c"]) == true ) {
     $Result = mysql_query("SELECT * FROM complaints WHERE id='" . $_GET["c"] . "'");
     if ( mysql_num_rows( $Result ) > 0 ) {
           $Data = mysql_fetch_row( $Result );      
           echo "<strong>" . $Data["title"] . "</strong><br />";
           echo $Data["content"];
     }
}
Post Reply