Login   Register  
PHP Classes
elePHPant
Icontem

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
 

Contents

Class file image Download
<?php
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 ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (isset(
$do) && $do == 'edit'
        
$user->updateData($fields$_POST$field_id);
    else 
        
$user->addData($fields$_POST);
    
    
header('Location: ' $_SERVER['PHP_SELF'] );
# end if

# handle data deletion
if (isset($do) && $do == 'del') {
    
$user->deleteData($field_id);
    
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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sample Data (Add/Edit/Delete)</title>
<style>
#header {
    font-weight:bold;
    }
    
#pointer {
    cursor: pointer;
    text-decoration: underline;
    color:#0000FF
    }
    
</style>
<script language="javascript" src="includes/js/confirm.js">/**confirm.js**/</script>
<script language="javascript" src="includes/js/validation.js">/**validation.js**/</script>
</head>
<div>
<h1>Sample Data (Add/Edit/Delete)</h1>
</div>

<div>
    <div><h2><?php echo $form_mode ?> Form</h2></div>
    <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>    
    </form>
    </div>
</div>
<br />
<div>
    <div><h2>LIST</h2></div>
    <div>

    <table border="1" cellpadding="4" cellspacing="0">
        <tr id="header">
            <td>ID</td>
            <td>First Name</td>
            <td>Last Name</td>
            <td>Email</td>
            <td>Phone</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <?php
        
if ($loop 0) {
            
# load list of data
            
for ($i=0$i<$loop$i++) {
        
?>
            <tr>
                <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>                
            </tr>
        <?php
            
# end for
        
# end if
        
?>
            
    </table>

    </div>
</div>

<body>
</body>
</html>