Four article classes encapsulate various actions on the article (insert database, remove from database, etc.)

Source: Internet
Author: User
Tags array count insert sql query reset
Insert | package | data | database <?php
//
// +----------------------------------------------------------------------+
// | Article Class |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 Netfish Software |
// | |
// | AUTHOR:WHXBB (whxbb@21cn.com) |
// +----------------------------------------------------------------------+
//
$Id: whxbb_article.class.php,v 0.1 2001/8/11 22:18:13 YF EXP $
//

Prohibit direct access to this page
if (basename ($HTTP _server_vars[' php_self ']) = = "whxbb_article.class.php") {
Header ("http/1.0 404 Not Found");
}


/**
* Article Class
* Purpose
* Encapsulation of the various operations of the article
*
*
* @author: WHXBB (whxbb@21cn.com)
* @version: 0.1
* @date: 2001/8/1
*/

Class Whxbb_article extends Whxbb
{
/** Page Object * *
var $pager;

function Article ()
{
$this->whxbb ();
}
/**
* Write the article to the database
* @param $title article title
* @param $author article author
* @param $content article content
* @return Operation Error: A Whxbb_error object succeeded: True
* @access Public
*/
function Insert ($title, $author, $content)
{
New Whxbb_debug ("Insert () Start");

Handling Incoming parameters
Whxbb::operatestring (& $title, ' in ');
Whxbb::operatestring (& $author, ' in ');
Whxbb::operatestring (& $content, ' in ');

$sql = "INSERT into article (title,author,content) VALUES (' $title ', ' $author ', ' $content ')";
if (! @mysql_query ($sql, $this->_conn))
{
return new Whxbb_error ("Insert () Failed." ( $sql) ", 1021);
}
New Whxbb_debug ("Insert () Completed");
return true;
}
/**
* Delete the specified record
* @param $id The ID of the record to delete
* @return Operation Error: A Whxbb_error object succeeded: True
* @access Public
*/
function Del ($id)
{
New Whxbb_debug ("Del ($id) Start");

$sql = "Delete from article where id= $id)";
if (! @mysql_query ($sql, $this->_conn))
{
Return to New Whxbb_error ("Del () Failed." ( $sql) ", 1024);
}
New Whxbb_debug ("Dle ($id) Completed");
return true;
}
/**
* Get the total number of articles
* @param $condition Query criteria
* @return Operation Error: A Whxbb_error object succeeded: True
* @access Public
*/
function GetCount ($condition = ')
{
New Whxbb_debug ("GetCount () Start");
$sql = "SELECT count (ID) from article where 1=1 $condition";
if (! $result = @mysql_query ($sql, $this->_conn))
{
return new Whxbb_error ("GetCount () Failed." ( $sql) ", 1000);
}
List ($count) = @mysql_fetch_array ($result);
@mysql_free_result ($result);
New Whxbb_debug ("GetCount () Completed");
return $count;
}

/**
* Get all the field information of an article
* @param $id Article ID number
* @return Operation Error: A Whxbb_error object succeeded: Returns an associative array cannot find information: returns 0
* @access Public
*/
function GetInfo ($id)
{
New Whxbb_debug ("GetInfo ($id) Start");
$sql = "SELECT ID, title, content, author from article where id= $id";
$result = @mysql_query ($sql, $this->_conn);
if (! $result)
return new Whxbb_error ("GetInfo ($id) Failed." ( $sql) ", 1002);

if (@mysql_num_rows ($result) = = 0)
return 0;

$info = @mysql_fetch_array ($result);
while (the list ($var, $key) = each ($info))
{
Whxbb::operatestring (& $info [$var], ' out ');
}
Reset ($info);
@mysql_free_result ($result);
New Whxbb_debug ("GetInfo ($id) Completed");
return $info;
}

/**
* Get all records author for the specified author name
* @param $items Display the number of bars per page, if 0 indicates that all records are removed
* @param page Current page number
* @param author author name
* @param $orderBy Sorting method
* @return Operation Error: A Whxbb_error object succeeded: Return an array cannot find information: returns 0
* @access Public
*/
function Getninfobyauthor ($items, $page, $author, $orderBy = ' ORDER BY id DESC ')
{
Whxbb::operatestring (& $author, ' in ');
$condition = "and author= ' $author '";
$result = $this->getninfo ($items, $page, $condition, $orderBy);
return $result;
}


}
/**
* List all records
* @param $items Display the number of bars per page, if 0 indicates that all records are removed
* @param $page Current page number
* @param $condition Query criteria
* @param $orderBy Sorting method
* @return Operation Error: A Whxbb_error object succeeded: Returns a two-dimensional array cannot find information: returns 0
* @access Public
*/
function Getninfo ($items, $page, $condition = ', $orderBy = ' ORDER BY id DESC ')
{
New Whxbb_debug ("Getninfo () Start");
$limit = ';
Total number of records taken
$infoCount = $this->getcount ($condition);
if ($infoCount = = 0)
return 0;

if ($items!= 0)
{
Create a new page splitter
$this->pager = new Pager ($infoCount, $items, $page);
$startPos = $this->pager->startpos;
$limit = "Limit". $startPos ",". $items;
}
$sql = "SELECT ID, title, author from article where 1=1 $condition $orderBy $limit";

$result = @mysql_query ($sql, $this->_conn);
if (! $result)
return new Whxbb_error ("Getninfo () Failed." ( $sql) ", 1001);

if (@mysql_num_rows ($result) = = 0)
return 0;
$i = 0;
while ($arr = @mysql_fetch_array ($result))
{
while (the list ($var, $key) = each ($arr))
{
Whxbb::operatestring (& $arr [$var], ' out ');
}
Reset ($arr);
$info [$i] = $arr;
$i + +;
}
@mysql_free_result ($result);
New Whxbb_debug ("Getninfo () Completed");
return $info;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.