Page 1 of 1

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

Posted: Thu Aug 26, 2010 9:18 pm
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

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

Posted: Fri Aug 27, 2010 12:22 am
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"];
     }
}