分类:
2005-08-05 11:06:15
CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
);
CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
);
*******************************************************/
printf( "
/* 设置数据库 */
mysql_pconnect( "", "httpd");
$Database = "yourdb";
/****************************************************************
一个吐出派生信息的递归函数
****************************************************************/
function showMessages($parentID)
{
global $Database;
$dateToUse = Date( "U");
echo "
/* 显示所有的类别 */
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE Parent=$parentID ";
$Query = $Query . "ORDER BY Created ";
$result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
while($RowCount < $numRows)
{
$messageID = mysql_result($result,$RowCount, "ID");
$messageTitle = mysql_result($result,$RowCount, "Title");
$messageCreated = mysql_result($result,$RowCount, "Created");
$messageParent = mysql_result($result,$RowCount, "Parent");
/*显示一行是什么类别的信息 */
printf( "
$RowCount++;
}
echo "
/****************************************************************
输出一个提交新信息的表单,并在其中预置一个父ID
****************************************************************/
function postForm($parentID, $useTitle)
{
printf( "
}
/******************************************************
执行动作
******************************************************/
if($ACTION != "")
{
if($ACTION == "POST")
{
$inputTitle = ereg_replace( "'", "''", $inputTitle);
$inputBody = ereg_replace( "'", "''", $inputBody);
$Query = "INSERT INTO bbsMessage ";
$Query .= "VALUES(0, '$inputTitle', ";
$Query .= "'$inputPoster', ";
$Query .= "now(), $inputParent, ";
$Query .= "'$inputBody')";
$result = mysql($Database,$Query);
}
}
/******************************************************
显示信息或者是显示信息列表
******************************************************/
if($messageID > 0)
{
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE ID=$messageID ";
$result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
if($RowCount < $numRows)
{
$messageID = mysql_result($result,$RowCount, "ID");
$messageTitle = mysql_result($result,$RowCount, "Title");
$messagePoster = mysql_result($result,$RowCount, "Poster");
$messageCreated = mysql_result($result,$RowCount, "Created");
$messageParent = mysql_result($result,$RowCount, "Parent");
$messageBody = mysql_result($result,$RowCount, "Body");
printf( "
Title | $messageTitle |
Poster | $messagePoster |
Posted | $messageCreated |
$messageBody |
postForm($messageID, "RE: $messageTitle");
}
echo "List of Messages
";
}
else
{
printf( "
/* 调用递归函数*/
showMessages(0);
postForm(0, "");
}
?>