Quick Search:
 
 PHP Code: Super Simple Database Driven Web Site Jump to:  
Category: >> PHP Code >> Super Simple Database Driven Web Site  

<< lastnext >>

Snippet Name: Super Simple Database Driven Web Site

Description: Make a MySQL Database called "db" with a table named "variables" with three rows ("id", "title", and "content"). Insert your data. Then call the page by going variables.php?id=1 etc.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?PHP 
 
$id = $_GET['id']; 
$id = PREG_REPLACE("/[^0-9]/i",'', $id);
 
$db = mysql_connect("localhost", "username", "password"); 
mysql_select_db("db",$db); 
 
$sql="SELECT * FROM variables WHERE id=" . $id; 
$result=mysql_query($sql,$db); 
 
$num = mysql_num_rows($result); 
$cur = 1; 
 
WHILE ($num >= $cur) { 
 
$row = mysql_fetch_array($result); 
 
$id = $row["id"]; 
$title = $row["title"]; 
$content = $row["content"]; 
 
ECHO "<li>Id = $id<br>"; 
ECHO "Title of page = $title<br>"; 
ECHO "Content = $content</li>"; 
 
$cur++; 
} 
 
?>
 


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org