<?php
// example1.php
//
// using EZ Select to generate queries based on some 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");
$my_query->add_where_clause("foo.name != 'foobar'");
// order by foo.id, then RAND()
$my_query->add_order_by("foo.id");
$my_query->add_order_by("RAND()");
$my_query->set_order_type("ASC");
// get first 25 results
$my_query->set_limit(0, 25);
// show our query
$my_query->show();
// at this point you would run the query through mysql_query() or whatever
// $result = mysql_query( $my_query->make() );
?>
|