Login   Register  
PHP Classes

File: sample_data.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mitchelle Pascual  >  MySQL DB Class and Data Manipulation Class  >  sample_data.php  >  Download  
File: sample_data.php
Role: Example script
Content type: text/plain
Description: sample script
Class: MySQL DB Class and Data Manipulation Class
MySQL wrapper with data manipulation functions
Author: By
Last change:
Date: 2007-02-12 15:55
Size: 4,228 bytes


Class file image Download
require 'init.php';

# create user object
$user = new Data('user_tbl');

# get all fields from user_tbl
$fields $user->getFields();

# get all data
$data_all $user->getAllData($fields);
$loop $user->getTotalData();

# init common vars
if (isset($_REQUEST['id']) && $_REQUEST['id'] != "") {
$id = (int) trim($_REQUEST['id']); 
$field_id = array('id'=>$id);
# end if
if (isset($_REQUEST['do']) && $_REQUEST['do'] != ""
$do = (string) strtolower(trim($_REQUEST['do']));

# handle data retrieval
if (isset($_GET['id']) && $_GET['id'] != "") {
$form_mode 'Update';
$id = (int) trim($_GET['id']); 
$field_id = array('id'=>$id);
$data $user->getOneData($fields$field_id);
} else {
$form_mode 'Add';
$data = array();
# end if

# handle data update/add
    if (isset(
$do) && $do == 'edit'
header('Location: ' $_SERVER['PHP_SELF'] );
# end if

# handle data deletion
if (isset($do) && $do == 'del') {
header('Location: ' $_SERVER['PHP_SELF'] );
# end if
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sample Data (Add/Edit/Delete)</title>
#header {
#pointer {
    cursor: pointer;
    text-decoration: underline;
<script language="javascript" src="includes/js/confirm.js">/**confirm.js**/</script>
<script language="javascript" src="includes/js/validation.js">/**validation.js**/</script>
<h1>Sample Data (Add/Edit/Delete)</h1>

    <div><h2><?php echo $form_mode ?> Form</h2></div>
    <form action="" method="post" name="frm">
        <input type="hidden" name="id" value="<?php echo isset($data['id']) ? $data['id'] : "" ?>" />
        <input type="hidden" name="do" value="<?php echo isset($_GET['do']) ? $_GET['do'] : "" ?>" />
        <div>*First Name: <br /><input type="text" name="first_name" value="<?php echo isset($data['first_name']) ? $data['first_name'] : "" ?>" /></div>
        <div>*Last Name:  <br /><input type="text" name="last_name" value="<?php echo isset($data['last_name']) ? $data['last_name'] : "" ?>" /></div>
        <div>*Email:  <br /><input type="text" name="email_add" value="<?php echo isset($data['email_add']) ? $data['email_add'] : "" ?>" /></div>
        <div>Phone:  <br /><input type="text" name="phone" value="<?php echo isset($data['phone']) ? $data['phone'] : "" ?>" /></div>
        <div><br /><input type="submit" value="<?php echo $form_mode ?>" onclick="YY_checkform('frm','first_name','#q','0','First Name is Required.','last_name','#q','0','Last Name is Required.','email_add','#S','2','Valid Email Address is Required.');return document.MM_returnValue" /> <input type="button" value="Cancel" onclick="window.location='<?php echo $_SERVER['PHP_SELF'?>'" /></div>    
<br />

    <table border="1" cellpadding="4" cellspacing="0">
        <tr id="header">
            <td>First Name</td>
            <td>Last Name</td>
if ($loop 0) {
# load list of data
for ($i=0$i<$loop$i++) {
                <td><?php echo $data_all[$i]['id'?></td>
                <td><?php echo $data_all[$i]['first_name'?></td>
                <td><?php echo $data_all[$i]['last_name'?></td>
                <td><?php echo $data_all[$i]['email_add'?></td>
                <td><?php echo $data_all[$i]['phone'?></td>
                <td><a id="pointer" href="<?php echo $_SERVER['PHP_SELF'?>?do=edit&id=<?php echo $data_all[$i]['id'?>">Edit</a></td>
                <td><a id="pointer" onclick="return confirmation();" href="<?php echo $_SERVER['PHP_SELF'?>?do=del&id=<?php echo $data_all[$i]['id'?>">Delete</a></td>                
# end for
# end if