PHP Classes

File: output.php

Recommend this page to a friend!
  Classes of Roberto Martinez  >  Code Help  >  output.php  >  Download  
File: output.php
Role: Sample output
Content type: text/plain
Description: Page Controller Result
Class: Code Help
Generate model, view and controller pattern code
Author: By
Last change:
Date: 17 years ago
Size: 4,507 bytes


Class file image Download
//output you should get from the sample
//added < ?    ? > marks and commented SQL at the bottom

    $model = new PersonModel();
    if (isset($submit)) {
       $model->setData($id, $name, $addr, $country, $status);
    	switch ($action) {
    	case 1:
    	header("Location: $PHP_SELF?id=$model->id&action=1");
    echo '<p><font class=title>Person</font></p>';

    if (isset($find)) {
        $view = new PersonView(&$model);
    $view = new PersonView(&$model);
    if (!isset($action)) $action=0;

class PersonModel {
var $id;
var $name;
var $addr;
var $country;
var $status;

function setData($id, $name, $addr, $country, $status) {
   $this->id = strtoupper($id);
   $this->name = strtoupper($name);
   $this->addr = strtoupper($addr);
   $this->country = strtoupper($country);
   $this->status = strtoupper($status);


function select($id) { 
   $this->id = $id; 
   $sql = 'SELECT * FROM person WHERE p_id= "'.$this->id.'"';
   $result = mysql_query($sql);
   $row = mysql_fetch_array($result);
   $this->name = $row['p_name'];
   $this->addr = $row['p_addr'];
   $this->country = $row['p_country'];
   $this->status = $row['p_status'];


function insert() { 
   $sql = 'INSERT INTO person SET 
   p_id = "'.$this->id.'", 
   p_name = "'.$this->name.'", 
   p_addr = "'.$this->addr.'", 
   p_country = "'.$this->country.'", 
   p_status = "'.$this->status.'"';
   $this->id = mysql_insert_id();

function update() { 
   $sql = 'UPDATE person SET 
   p_name= "'.$this->name.'", 
   p_addr= "'.$this->addr.'", 
   p_country= "'.$this->country.'", 
   p_status= "'.$this->status.'" 
   WHERE p_id = "'.$this->id.'"';

function result($find) { 
   $sql = 'SELECT * FROM person ';
   if ($find>'')$sql.='WHERE p_name LIKE "'.$find.'%"';
   return $result;}


class PersonView {
var $model;

function PersonView($model) { 
   $this->model = $model;

function show() { 
   echo '<a href='.$PHP_SELF.'?id='.$this->model->id.'&action=1>Editar</a> | 
   <a href='.$PHP_SELF.'?action=2>Nuevo </a>
   <table border="0" cellspacing="1" width="50%">
   <tr><th colspan=2>Person</th></tr>

function edit($action) { 
   echo '<form method=post action='.$PHP_SELF.'>
   <input type=text name=find> <input type=submit name=search value=Buscar>
   <form method=post action='.$PHP_SELF.'?action='.$action.'>
   <input type=hidden name=id value='.$this->model->id.'>
   <input type=submit name=submit value=Guardar>
   <table border="0" cellspacing="1" width="50%">
   <tr><th colspan=2>Person</th></tr>
      <input type=text name=name value="'.$this->model->name.'"></td></tr>
      <input type=text name=addr value="'.$this->model->addr.'"></td></tr>
      <input type=text name=country value="'.$this->model->country.'"></td></tr>
      <input type=text name=status value="'.$this->model->status.'"></td></tr>
function browse($result) { 
   echo '<table border="0" cellspacing="1" width="100%">
   while ($row=mysql_fetch_array($result)) {
      echo '<tr><td><a href='.$PHP_SELF.'?id='.$row['p_id'].'&action=1>'.$row['p_name'].'</a></td>
   echo '</table>';

CREATE TABLE person ( p_id int(6) NOT NULL AUTO_INCREMENT , p_name char(8), p_addr text, p_country text, p_status char(1), PRIMARY KEY (p_id));
For more information send a message to info at phpclasses dot org.