note 66749 added to language.oop
| From: | phenixcm at hotmail dot com | Date: | Sat, 27 May 2006 23:20:01 +0000 |
| Subject: | note 66749 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-112418@lists.php.net to get a copy of this message | ||
##PG1##
Here are 3 classes made in php4 (before php5) to display a list of question/answer from a DB.
The first one is the main class, the second one access to one element thanks to its ID number, and
the last one retrieve all elements from DB.
#######################################
Class Help
{
var $id,$pid,$question,$answer;
function Help($num,$p,$quest,$ans) {
$this->id=$num;
$this->pid=$p;
$this->question=$quest;
$this->answer=$ans;
}
function add() {
require("connection.php");
$query="INSERT INTO p_Help VALUES('','"
.$this->pid."','"
.$this->question."','"
.$this->answer."')";
mysql_query($query) or header("Location: failed.php?msg=...");
return true;
}
function read() {
require("connection.php");
$query="SELECT * FROM p_Help WHERE help_id='".$this->id."'";
$result=mysql_query($query) or header("Location: failed.php?msg=...");
$line=mysql_fetch_row($result);
$this->id=$line[0];
$this->pid=$line[1];
$this->question=$line[2];
$this->answer=$line[3];
mysql_free_result($result);
return true;
}
function update() {
require("connection.php");
$query="UPDATE p_Help SET
help_pid='".$this->pid."',help_question='"
.$this->question."',help_answer='".$this->answer."' WHERE
help_id='"
.$this->id."'";
mysql_query($query) or header("Location: failed.php?msg=...");
return true;
}
function del() {
require("connection.php");
$query="DELETE FROM p_Help WHERE help_id='".$this->id."'";
mysql_query($query) or header("Location: failed.php?msg=...");
return true;
}
}
Class HelpId extends Help
{
var $id;
function HelpId($id) {
$this->id=$id;
new Help($id,"","","");
}
}
Class Helps
{
var $hlp,$constraint,$field;
function Helps() {
$this->hlp=array();
$this->constraint="0";
$this->field="0";
}
function read() {
require("connection.php");
$query="SELECT ".(($this->field!="0")?($this->field):("*"))
." FROM p_Help".(($this->constraint!="0")?("
".$this->constraint):(""));
$result=mysql_query($query) or header("Location: failed.php?msg=...");
if(mysql_num_rows($result)>0)
while($row=mysql_fetch_row($result)) {
$hlps=new HelpId($row[0]);
$hlps->read();
array_push($this->hlp,$hlps);
}
else $this->hlp="0";
mysql_free_result($result);
}
function size() {
if($this->hlp=="0") return 0;
else return count($this->hlp);
}
function constraint($c) { $this->constraint=$c; }
function field($f) { $this->field=$f; }
}
## Next on PG2##
----
Server IP: 217.174.203.10
Probable Submitter: 81.56.15.249
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit -- http://master.php.net/note/edit/66749
Del: integrated -- http://master.php.net/note/delete/66749/integrated
Del: useless -- http://master.php.net/note/delete/66749/useless
Del: bad code -- http://master.php.net/note/delete/66749/bad+code
Del: spam -- http://master.php.net/note/delete/66749/spam
Del: non-english -- http://master.php.net/note/delete/66749/non-english
Del: in docs -- http://master.php.net/note/delete/66749/in+docs
Del: other reasons-- http://master.php.net/note/delete/66749
Reject -- http://master.php.net/note/reject/66749
Search -- http://master.php.net/manage/user-notes.php