Hi.
I want to do something really simple. I want to be able to write
a custom SQL query in a textbox on a webpage, submit it and then output to
the webpage in the format of MySQL output i.e. like this
+--------+--------+
| str_id | fd |
+--------+--------+
| 1062 | 9.996 |
| 2701 | 10.000 |
| 2704 | 9.999 |
| 4185 | 9.984 |
| 5509 | 9.998 |
| 6477 | 9.999 |
+--------+--------+
6 rows in set (0.03 sec)
so my webpage for input looks like this
<h2>Enter your own SQL text here</h2>
<form action="query_p age_custom.php" method="post">
<textarea cols=80 rows=20 name=sqltext></textarea>
<input type="submit" name="submit" value="Go">
</form>
and my query_page_cust om.php looks like this:
<?php
$db_connection = mysql_connect ('localhost','' , '') or die (mysql_error()) ;
$db_select = mysql_select_db ('SILVER') or die (mysql_error()) ;
if (!isset($sqltex t)) {
echo 'No text entered<br>'."\ n";
}
// run query
$result = mysql_query($sq ltext) or die(mysql_error ());
if ($row = mysql_fetch_ass oc($result)) {
do {
echo '<br>';
foreach($row as $outputline){
echo("$outputli ne ");
}
} while($row = mysql_fetch_arr ay($result));
} else {print "Sorry, query did not return any rows!";}
but instead of the echo outputline I want to return the results the same way
as MySQL outputs it. Is this possible?
Do I have to output the data into a file and then view the file?
thanks for any help.
Martin.
I want to do something really simple. I want to be able to write
a custom SQL query in a textbox on a webpage, submit it and then output to
the webpage in the format of MySQL output i.e. like this
+--------+--------+
| str_id | fd |
+--------+--------+
| 1062 | 9.996 |
| 2701 | 10.000 |
| 2704 | 9.999 |
| 4185 | 9.984 |
| 5509 | 9.998 |
| 6477 | 9.999 |
+--------+--------+
6 rows in set (0.03 sec)
so my webpage for input looks like this
<h2>Enter your own SQL text here</h2>
<form action="query_p age_custom.php" method="post">
<textarea cols=80 rows=20 name=sqltext></textarea>
<input type="submit" name="submit" value="Go">
</form>
and my query_page_cust om.php looks like this:
<?php
$db_connection = mysql_connect ('localhost','' , '') or die (mysql_error()) ;
$db_select = mysql_select_db ('SILVER') or die (mysql_error()) ;
if (!isset($sqltex t)) {
echo 'No text entered<br>'."\ n";
}
// run query
$result = mysql_query($sq ltext) or die(mysql_error ());
if ($row = mysql_fetch_ass oc($result)) {
do {
echo '<br>';
foreach($row as $outputline){
echo("$outputli ne ");
}
} while($row = mysql_fetch_arr ay($result));
} else {print "Sorry, query did not return any rows!";}
but instead of the echo outputline I want to return the results the same way
as MySQL outputs it. Is this possible?
Do I have to output the data into a file and then view the file?
thanks for any help.
Martin.
Comment