IPT home IPT A Virtual Approach by Peter Whitehouse
Quick Links:
 
 
PHP home
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help
 
 

The Q Engine

Music Database


The Code this form runs looks like this:

<form action="blah.php" method="post">
  <textarea name="query" rows="10" cols="80">select
</textarea>
  <br>
  <input type=submit value="Post My Query">
</form>


***
Where the PHP script in blah.php looks like:
***

 <?php
 /*
 * Uberfast ultracraptastic mysql adhoc [q]uery engine
 */

 $link = mysql_connect("localhost", "username", "password")  or die("Unable to connect");
 print "Connected  successfully | <a href="q.php">BACK</a><p>";

 mysql_select_db("dbname") or die("Unable to select database");

 $query = stripslashes($HTTP_POST_VARS[query]);

 $result = mysql_query($query);

 $rows = mysql_num_rows($result);
 print "There are  $rows rows<p>";

 $columns = mysql_num_fields($result);

 print "Query:  $query";
 
 if ($rows > 0) {
    print "<p> <table border=1><tr>";
    for ($x = 0; $x < $columns; $x++) {
        print "<th>";
        $name = mysql_field_name($result,$x);
        print "$name";
        print "</th>"; 
    }
    print "</tr>";
    while ($row = mysql_fetch_row($result)) {
        print "<tr>";
        for ($y =0; $y < $columns; $y++) { 
            print "<td>$row[$y]</td>  ";
        }
        print "</tr>";
    }//end while 
    print "</table>";
 } //end if
?>
</body>
</html>

The original code for this query engine was kindly written by Mr Quentin Cregan ('Q') - thanks mate!

 

wonko@wonko.info
©Copyright 1992..2010. Edition 18.18.220710
wonkosite
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License
.