note 66749 deleted from language.oop by bjori

From: Date: Sun, 28 May 2006 11:03:31 +0000
Subject: note 66749 deleted from language.oop by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112440@lists.php.net to get a copy of this message
Note Submitter: phenixcm at hotmail dot com Reason: useless ---- ##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##

« previous php.notes (#112440) next »