By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

print output in MySQL format

P: n/a
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_page_custom.php" method="post">
<textarea cols=80 rows=20 name=sqltext></textarea>
<input type="submit" name="submit" value="Go">
</form>

and my query_page_custom.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($sqltext)) {
echo 'No text entered<br>'."\n";
}

// run query
$result = mysql_query($sqltext) or die(mysql_error());

if ($row = mysql_fetch_assoc($result)) {

do {
echo '<br>';
foreach($row as $outputline){
echo("$outputline &nbsp;");
}
} while($row = mysql_fetch_array($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.
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
With total disregard for any kind of safety measures
md********@netscape.net (Martin Foster) leapt forth and uttered:
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_page_custom.php" method="post">
<textarea cols=80 rows=20 name=sqltext></textarea>
<input type="submit" name="submit" value="Go">
</form>

and my query_page_custom.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($sqltext)) {
echo 'No text entered<br>'."\n";
}

// run query
$result = mysql_query($sqltext) or die(mysql_error());

if ($row = mysql_fetch_assoc($result)) {

do {
echo '<br>';
foreach($row as $outputline){
echo("$outputline &nbsp;");
}
} while($row = mysql_fetch_array($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.


Try this:
http://cvs.php.net/co.php/pear/DBA_R...lbox.php?r=1.6

--
There is no signature.....
Jul 17 '05 #2

P: n/a
Phil Roberts <ph*****@HOLYflatnetSHIT.net> wrote in message news:<Xn*************************@216.196.97.132>. ..
With total disregard for any kind of safety measures
md********@netscape.net (Martin Foster) leapt forth and uttered:
How do you mean? What safety measures?

Are you saying, its not as simple as I thought?
I guess not! :-)

Thankyou for the link to the toolbox. I'll give it try.
I tried a work around the problem by using

mysql -t > outputfile and then viewing the outputfile.

cheers,
Martin.
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_page_custom.php" method="post">
<textarea cols=80 rows=20 name=sqltext></textarea>
<input type="submit" name="submit" value="Go">
</form>

and my query_page_custom.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($sqltext)) {
echo 'No text entered<br>'."\n";
}

// run query
$result = mysql_query($sqltext) or die(mysql_error());

if ($row = mysql_fetch_assoc($result)) {

do {
echo '<br>';
foreach($row as $outputline){
echo("$outputline &nbsp;");
}
} while($row = mysql_fetch_array($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.


Try this:
http://cvs.php.net/co.php/pear/DBA_R...lbox.php?r=1.6

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.