<?
/*
news donkey v1.0 d8b db d88888b db d8b db .d8888.
by oscar rylin [oscar@mgon.com] 888o 88 88' 88 i8i 88 88' yp
88v8o 88 88ooooo 88 i8i 88 `8bo.
88 v8o88 88~~~~~ y8 i8i 88 `y8b.
88 v888 88. `8b d8'8b d8' db 8d
vp v8p y88888p `8b8' `8d8' `8888y'
d8888b. .d88b. d8b db db dd d88888b db db
88 `8d .8p y8. 888o 88 88 ,8p' 88' `8b d8'
88 88 88 88 88v8o 88 88,8p 88ooooo `8bd8'
88 88 88 88 88 v8o88 88`8b 88~~~~~ 88
88 .8d `8b d8' 88 v888 88 `88. 88. 88
y8888d' `y88p' vp v8p yp yd y88888p yp
this script was made by oscar rylin (oscar@mgon.com) while learning php w/
mysql connections.
what the script does:
* provides an easy way to read news from a mysql database
* prints it out in a nice html format which is customizable
* provides a secure interface (user/password validation through a mysql db)
* updating news, deleting and adding users and lots of other stuff
*/
include "dbconn.php"; // this is http://zend.com/codex.php?id=35&single=1
include "settings.php"; // the settings file
?>
<html>
<head>
<title>newsm0nger1.0</title>
<style type="text/css">
.section { font-weight: bold; font-size:10pt; }
.newstxt { font-weight: normal; font-size:10pt; color: #ffffff; font-family: verdana; }
a { font-weight: bold; font-size:10pt; color: #ffffff; font-family: verdana; }
a.normal { font-weight: bold; font-size:10pt; color: #000000; font-family: verdana; }
</style>
</head>
<body bgcolor="white">
<? print $header; ?>
<center>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="black">
<?
$db = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$result = mysql_query("select count(id) as total from news",$db);
$row = mysql_fetch_array($result);
mysql_close($db);
if ($row[total] > 5) {
$pcount = 0;
print "<b>archive</b> ?";
print "<a href=\"$php_self?start=0\" class=\"normal\">main</a> ";
while ($pcount < ($row[total]/5)-1) {
++$pcount;
print "<a href=\"$php_self?start=". ($pcount*5) ."\" class=\"normal\">$pcount</a> ";
}
}
$tmpdl = 0;
$sql = new cdbmysql($dbhost, $dbuser, $dbpass, $dbname);
if ($start) {
$sql -> query ("select * from news where id < ". ($row[total] - $start) . " order by id desc");
} else {
$sql -> query ("select * from news order by id desc");
}
while (($sql -> readrow()) && ($tmpdl < $newsdl)) {
$id = ($sql -> rowdata["id"]);
$date = ($sql -> rowdata["date"]);
$poster = ($sql -> rowdata["user"]);
$header = ($sql -> rowdata["header"]);
$news = ($sql -> rowdata["news"]);
$news = nl2br($news);
$udb = new cdbmysql($dbhost, $dbuser, $dbpass, $dbname);
$udb -> query ("select * from users where user=\"$poster\"");
while ($udb -> readrow()) {
$email = ($udb -> rowdata["email"]);
}
$udb -> close();
$format = "
<tr>
<td width=\"579\" height=\"20\" background=\"section.gif\" class=\"section\" colspan=\"2\">
<font color=\"white\">$date</font> - <font color=\"#003366\">$header</font>
</td>
</tr>
<tr>
<td bgcolor=\"#666688\" class=\"newstxt\" colspan=\"2\">
$news
<br>
-- <a href=\"mailto:$email\">$poster</a>
</td>
</tr>
<tr>
<td bgcolor=\"#ffffff\" height=\"20\" colspan=\"2\">
</td>
</tr>
";
print "$format";
++$tmpdl;
}
//$sql -> close();
?>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="579">
<tr><td width="50%" align="left"><img src="php.gif"></td><td width="50%" align="right"><img src="mysql.gif"></td></tr>
</table>
</center>
<? print $footer; ?>
</body>
</html>