Connecting Tech Pros Worldwide Forums | Help | Site Map

print output in MySQL format

Martin Foster
Guest
 
Posts: n/a
#1: Jul 17 '05
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.

Phil Roberts
Guest
 
Posts: n/a
#2: Jul 17 '05

re: print output in MySQL format


With total disregard for any kind of safety measures
mdfoster44@netscape.net (Martin Foster) leapt forth and uttered:
[color=blue]
> 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.
>[/color]

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

--
There is no signature.....
Martin Foster
Guest
 
Posts: n/a
#3: Jul 17 '05

re: print output in MySQL format


Phil Roberts <philrob@HOLYflatnetSHIT.net> wrote in message news:<Xns9471EFBC66754philroberts@216.196.97.132>. ..[color=blue]
> With total disregard for any kind of safety measures
> mdfoster44@netscape.net (Martin Foster) leapt forth and uttered:[/color]

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.
[color=blue]
>[color=green]
> > 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 |[/color]
> +--------+--------+[color=green]
> >| 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.
> >[/color]
>
> Try this:
> http://cvs.php.net/co.php/pear/DBA_R...lbox.php?r=1.6[/color]
Closed Thread