Mega Code Archive

 
Categories / Php / Functions
 

SIMPLE Databse Driven Web Site

<?php // 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. $id = $_GET['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++; } ?>