PHP Classes

File: 01_mysql_listing_sample.php

Recommend this page to a friend!
  Classes of J.B.  >  Simple Object  >  01_mysql_listing_sample.php  >  Download  
File: 01_mysql_listing_sample.php
Role: Example script
Content type: text/plain
Description: SimpleObject in use: list MySQL table records in three lines of code
Class: Simple Object
Base class with common variable access functions
Author: By
Last change: Changed require_once('mysqlresultiterator.php'); to require_once('simplemysqlresultiterator.php');
Date: 18 years ago
Size: 1,621 bytes


Class file image Download
# This script shows how use of SimpleObject and its child classes
    # may ease your programming
    # TASK 1 - List all mysql table records
    # include all required classes
# Connect to mysql
# Write down your SQL query:
$query = "SELECT * FROM my_table";
# Create an instance of list template:
    # Send an instance of MysqlResultIterator as argument
$list_tpl =& new ListTemplate(new SimpleMysqlResultIterator($query));
# Set title (variable in template) to list
$list_tpl->set('list_title','What a Simple List!');
# Display the list of items:
# That's it!
    # Don't forget to make list_template.html and item_template.html
    # files such that they have markers like <!--$field_name--> in
    # item_template.html and <!--$list--> and <!--$list_title-->
    # in list_template.html. <!--$list--> will be replaced by output
    # of item listing:
        <p>Here are the records from table:</p>
            <th>record id</th>
            <th>record title</th>
        !! modify id and title to names of fields in your mysql table

For more information send a message to info at phpclasses dot org.