| |||||||||||
| |||||||||||
Application to look after generalise casual queries on a complex table structure
PHP and MySQL example application - adhoc database analysis example from a Well House Consultants training course
More on PHP and MySQL example application - adhoc database analysis [link] Source code: adhoc_sql_query_engine.php Module: H204
<?php
# Settings that may be changed between installations $include_from = "$_SERVER[DOCUMENT_ROOT]/../demoprivate"; # Typical production $include_from = "."; # for testing - in CURRENT directory $dbsource = "localhost"; $dbuser = "trainee"; $dbpass = "abc123"; $dbname = "forsale"; # END of settings that may vary from one installation to another require_once ("$include_from/webhelpers.inc"); require_once ("$include_from/businesslogic.inc"); # Top level application code $_warnings = array(); session_start(); // Set up for a newcomer or someone following a link or typing a URL if (! $_SESSION[current] or $_SERVER[REQUEST_METHOD] == "GET") { $current = 0; read_config("$include_from/adhoc.conf"); } else { $current = $_SESSION[current]; } $fill[date] = date("r"); $fill[basetext] = "SQL Ad-hoc Query System"; if ($_SESSION[config]["basetext:"][0]) ( $fill[basetext] = $_SESSION[config]["basetext:"][0]) ; ######################### Handler responses from previous form $error = 0; switch ($current) { case 0: // Finish up from initialisation $current = 1; break; case 1: // Has the user entered a valid login code? $role = validate_login(); if (! $error) { $current = 10; if ($role == "admin") $current = 101; store_login(); } break; case 10: // Finish up from choosing base query $tuneit = validate_base(); if (! $error) { $current = 11; if ($tuneit == 0) $current = 20; store_base(); } break; case 11: // Finish up from record selection (WHERE clauses) validate_rows(); if (! $error) { $current = 12; # For full app, move to columns store_rows(); } break; case 12: // Finish up from field selection (which columns) validate_cols(); if (! $error) { $current = 13; $current = 20; # for testing, go to do the jobbie! store_cols(); } break; case 13: // Finish up from grouping validate_groups(); if (! $error) { $current = 20; store_groups(); } break; case 20: // Finish up from results $whatnext = validate_results(); if (! $error) { if ($whatnext == "next") $current = 20; if ($whatnext == "previous") $current = 20; if ($whatnext == "all") $current = 20; if ($whatnext == "tune") $current = 11; if ($whatnext == "new") $current = 10; if ($whatnext == "logout") $current = 199; store_results(); } break; default: print "Looking to complete page '$current'. Not yet implemented."; break; } # activity_log(); $_SESSION[current] = $current; $fill[current] = $current; $fill[alert] = ""; $fill[user] = $_SESSION[user]; ######################### Prepare for next form switch ($current) { case 1: // prepare for login $fill[form] = makeform_login(); $fill[instruct] = "Please login or select <a href=/>here</a>". " if you are not an authorised user"; $fill[result] = "-"; $fill[user] = "[not logged in]"; break; case 10: // select base query $fill[form] = makeform_basequery(); $fill[instruct] = "Please choose a base or archive query or NEW"; $fill[result] = "-"; break; case 11: // select rows $fill[form] = makeform_rows(); $fill[instruct] = "Please select which rows are required"; $fill[result] = "-"; break; case 12: // select columns $fill[form] = makeform_cols(); $fill[instruct] = "Please select which fields to be displayed"; $fill[result] = "-"; break; case 13: // select grouping $fill[form] = makeform_grouping(); $fill[instruct] = "Please select how rows are to be grouped"; $fill[result] = "-"; break; case 20: // Generate Result $fill[form] = makeform_result(); $fill[instruct] = "What do you want to do now?"; $fill[result] = run_query(); break; case 199: $fill[form] = ""; $fill[instruct] = "Have a nice day!<br>"; $fill[result] = "You may <a href=$PHP_SELF>log in again</a> or "; $fill[result] .= "<a href=/>go to home page</a><br>"; $fill[user] = "[not logged in]"; session_destroy(); break; default: print "Oh dear - failed to prepare for '$current'!"; break; } ######################### Send response $fill[errmsg] = $error ? "Error - please correct as indicated" : ""; $html = generate_output("$include_from/page_layout.htp",$fill); print $html; ?> Learn about this subject
This module and example are covered on the following public courses:
* Learning to program in PHP * PHP Programming Also available on on site courses for larger groups Books covering this topic
Yes. We have over 700 books in our library. Books
covering PHP are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "PHP and MySQL example application - adhoc database analysis" training module. You'll find a description of the topic and some
other closely related examples on the "PHP and MySQL example application - adhoc database analysis" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Web site author
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.info/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |