Formatting MySQL Queries
am 24.01.2007 22:20:44 von Brent Anderson
Hello.
My team and I are looking for a way to return an entire table of
MySQL data with columns delimited by tabs and rows delimited by
carriage returns. How exactly would this work - I'm not a PHP expert
and, although I know MySQL, I don't know where to begin with
formatting a query pointer into an actual pile of text. We have an
engine ready to take tables in this format for processing, we just
need to parse the query data into a text result.
Thanks,
Brent Anderson
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Formatting MySQL Queries
am 24.01.2007 22:46:38 von Jeremy Glover
// Make sure you're already connected to the database...
=09
function return_mysql_table($table_name, $id_column)
{
$sql =3D "SELECT * FROM " . $table_name . " ORDER BY " .
$id_column . " ASC";
$result =3D mysql_query($sql) or die("Error: Invalid SQL:
" . $sql);
=09
$rows =3D array();
=09
while($current_row =3D mysql_fetch_array($result))
{
$rows[] =3D implode("\t", $current_row);
}
=09
$table =3D implode("\r\n", $rows);
=09
return $table;
}
?>=20
-----Original Message-----
From: Brent Anderson [mailto:brentj84062@gmail.com]=20
Sent: Wednesday, January 24, 2007 4:21 PM
To: php-db@lists.php.net
Subject: Formatting MySQL Queries
Hello.
My team and I are looking for a way to return an entire table of MySQL
data with columns delimited by tabs and rows delimited by carriage
returns. How exactly would this work - I'm not a PHP expert and,
although I know MySQL, I don't know where to begin with formatting a
query pointer into an actual pile of text. We have an engine ready to
take tables in this format for processing, we just need to parse the
query data into a text result.
Thanks,
Brent Anderson
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeremy Glover
Interactive Communication Developer, Trone
336.819.6934
jglover@trone.com
Confidentiality Notice: This e-mail communication and any attachments =
may contain confidential and privileged information for the use of the =
designated recipients named above. If you are not the intended =
recipient, you are hereby notified that you have received this =
communication in error and that any review, disclosure, dissemination, =
distribution or copying of it or its contents is prohibited. If you =
have received this communication in error, please notify me immediately =
by replying to this message and deleting it from your computer. Thank =
you.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting MySQL Queries
am 24.01.2007 22:51:45 von Brent Anderson
Hello.
Just as I posted this, I found a MySQL example on php.net and was
able to modify it to fit my needs. Here is the script:
// Connecting, selecting database
$link = mysql_connect('server', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in Tab/Return delimited format
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// echo "\t
\n";
foreach ($line as $col_value) {
echo "$col_value\t";
}
echo "\n";
}
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
Thanks to Steven Cruz and Jeremy Glover for their quick replies, but
this will be perfect.
Thanks,
Brent Anderson
On Jan 24, 2007, at 2:20 PM, Brent Anderson wrote:
> Hello.
>
> My team and I are looking for a way to return an entire table of
> MySQL data with columns delimited by tabs and rows delimited by
> carriage returns. How exactly would this work - I'm not a PHP
> expert and, although I know MySQL, I don't know where to begin with
> formatting a query pointer into an actual pile of text. We have an
> engine ready to take tables in this format for processing, we just
> need to parse the query data into a text result.
>
> Thanks,
> Brent Anderson
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Formatting MySQL Queries
am 24.01.2007 23:07:35 von Niel Archer
Hi
SELECT * FROM table INTO OUTFILE 'file_name'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
Niel
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php