Login   Register  
PHP Classes
elePHPant
Icontem

File: example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Pineapple Technologies  >  EZ Select  >  example2.php  >  Download  
File: example2.php
Role: ???
Content type: text/plain
Description: example 2
Class: EZ Select
Author: By
Last change:
Date: 12 years ago
Size: 1,344 bytes
 

Contents

Class file image Download
<?php
// example2.php
//
// using EZ Select to generate queries based on some user input.
//
// Assumes tings like $dont_show_foobars, $order_by, $num_result, etc.
// came from a form or some sort of user input

require("ez_select.php");

$my_query = new ez_select();

// we want to select from "foo" and "bar" tables
$my_query->add_table("foo");
$my_query->add_table("bar");

// add the fields we want to select
$my_query->add_field("foo.id");
$my_query->add_field("foo.name");
$my_query->add_field("bar.id");

// where clauses to restrict our query
$my_query->add_where_clause("foo.id = bar.id");

if( isset($dont_show_foobars) )
{
	$my_query->add_where_clause("foo.name != 'foobar'");
}

// how did they want to order the results?
switch( $order_by )
{

	case 'foo.id':

		$my_query->add_order_by("foo.id");

	break;

	case 'foo.name':

		$my_query->add_order_by("foo.name");

	break;

	default:

		$my_query->add_order_by("RAND()");
	
	break;

}

// how many results to show?
if( $num_results )
{
	$my_query->set_limit(0, $num_results);
}
// or do 25 by default
else
{
	$my_query->set_limit(0, 25);
}

// Let's see our query
$my_query->show();

// at this point you would run the query through mysql_query() or whatever
// $result = mysql_query( $my_query->make() );

?>