print output in MySQL format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Foster

    print output in MySQL format

    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 &nbsp;");
    }
    } 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.
  • Phil Roberts

    #2
    Re: print output in MySQL format

    With total disregard for any kind of safety measures
    mdfoster44@nets cape.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_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 &nbsp;");
    > }
    > } 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.
    >[/color]

    Try this:


    --
    There is no signature.....

    Comment

    • Martin Foster

      #3
      Re: print output in MySQL format

      Phil Roberts <philrob@HOLYfl atnetSHIT.net> wrote in message news:<Xns9471EF BC66754philrobe rts@216.196.97. 132>...[color=blue]
      > With total disregard for any kind of safety measures
      > mdfoster44@nets cape.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_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 &nbsp;");
      > > }
      > > } 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.
      > >[/color]
      >
      > Try this:
      > http://cvs.php.net/co.php/pear/DBA_R...lbox.php?r=1.6[/color]

      Comment

      Working...