I wan to add a feature (for ease of use) that will allow me to type in any query on a webpage and display the results. I thought it would be simple enough but I have only found examples on displaying results from hard-coded queries and I am already able to do that.
What I'm basically looking to do is have a textbox that captures the query. So if i type:
SHOW Tables;
and then hit submit it will show all my tables, but it should also handle results for
SELECT * FROM <table> WHERE ...;
I have done this which kind of works - but not quite.
$theQuery = $_POST['textfield'];
$result = mysql_query($theQuery);
//$row = mysql_fetch_array($result);
while( $queryContent = mysql_fetch_row( $result ) )
{
// Display.
$i = 0;
while($i<sizeof($queryContent))
{
echo $queryContent[$i];
echo " ***** ";
$i++;
}
echo "<br>";
}
Also, The first row seems messed up and it does not display column names which are a big help. I have $i set up to go through each column because each query can have different numbers of column. Doing a select on a 'logins' table may return 2 columns whereas a select on 'items' may return 5 columns.
I appreciate any feedback and thank you in advance for your time helping me to solve this.