Re: Formatting MySQL Queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

<?php
// 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<tr>\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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux