Multi-Layer SQL Example

<html> <head> <title>Current Posts</title> </head> <body> <h1>Current Posts</h1> <?php $db = mysql_connect("localhost:/export/mysql/mysql.sockss"); mysql_select_db("forum", $db); $sql = "SELECT subject, body" . " FROM Posts"; $rows = mysql_query($sql, $db); if(!$rows) { echo "<p>SQL error: " . mysql_error() . "</p>\n"; } elseif(mysql_num_rows($rows) == 0) { echo "<p>There are not yet any posts.</p>\n"; } else { $row1 = 0; while($row1 < mysql_num_rows($rows)) { $post_subject = mysql_result($rows, $row1, 0); $post_body = mysql_result($rows, $row1, 1); echo "<h2>$post_subject</h2>\n"; echo "<p>$post_body</p>\n"; $row1= $row1 + 1; } } ?> </body> </html>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.