I'm trying to get my head around php classes. I want to write a small php
file (call it genericly uniquepagesomething.php) that will call the
pagemaker.class. For example Apples3.php that calls pagemaker.class. In
pagemaker.class, it will look up page 3 of the topic apples from a table
and get the text file. It will also look up the proper template to
use. pagemaker.class will then insert the text file into the template and
print it out to the browser.
Here is what I have cobbled together so far from various things i've read.
--------- uniquepagesomething.php --------
<?php
require("pagemaker.class");
$pagemaker = new pagemaker;
$pagemaker->find($findpage, $pagesomething);
$pagemaker->make("pagesomething");
?>
--------- pagemaker.class --------
<?php
class pagemaker
var $Host = ""; // Hostname of our MySQL server.
var $Database = ""; // Logical database name on that server.
var $User = ""; // User und Password for login.
var $Password = "";
var $Link_ID = 0; // Result of mysql_connect().
var $Query_ID = 0; // Result of most recent mysql_query().
var $Record = array(); // current mysql_fetch_array()-result.
var $Row; // current row number.
var $Errno = 0; // error state of query...
var $Error = "";
function find($findpage,$pagesomething) {
$this->$findpage=$pagesomething; //fix this to split the
topic and page number
$this->$Query_String="select tmplt, image, file, desc from
pages where "; //fix this too
$this->connect();
# printf("Debug: query = %s<br>n", $Query_String);
$this->Query_ID =
mysql_query($this->Query_String,$this->Link_ID);
$this->Row = 0;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
if (!$this->Query_ID) {
$this->halt("Invalid SQL: ".$Query_String);
}
return $this->Query_ID;
}
function halt($msg) {
printf("<b>Database error:</b> %s<br>\n", $msg);
printf("<b>MySQL Error</b>: %s (%s)<br>\n",
$this->Errno,
$this->Error);
die("Session halted.");
}
function connect() {
if (0 == $this->Link_ID ) {
$this->Link_ID=mysql_connect($this->Host, $this->User,
$this->Password);
if (!$this->Link_ID) {
$this->halt("Link-ID == false, connect failed");
}
if (!mysql_query(sprintf("use
%s",$this->Database),$this->Link_ID)) {
$this->halt("cannot use database ".$this->Database);
}
}
}
find();
?>
Is this going anywhere in the right direction?
any comments are welcome
Thanks
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php