[thelist] mysql to ms word for merge letter
Joe Crawford
jcrawford at avencom.com
Wed Apr 18 05:08:55 CDT 2001
on 4/18/01 2:49 AM, Adrian Fischer at adrian at logo-logic.com wrote:
> Thanks Joe...does it matter that my db is hosted somewhere else?
To connect to a remote database you generally need:
hostname
username
password
And the remote database needs to be able to accept outbound connections.
> *Theoretically* are you saying I can use the ODBC to dynamically link my
> word document on my win_pc to my db on the internet (I have permanent cable
> connection) or was that just wishful thinking on my part?
Maybe not a permanent connection, but one you can log into as you see fit.
Be aware that there are security issues whenever you're putting db traffic
over the net.
> Or are you saying
> I can create a CSV file on the server then link to that...am I sounded as
> though I don't know what I'm talking about (for very good reason)? If so
> would there be any chance of taking a peek at he php you used?
I just made a page to dynamically create a CSV (well, tab delimited) file I
can use. The code below is really ugly. But it has the steps. I create a
little function to echo either data and a tab, or if a field is blank, just
a tab.
Then my query.
Then my connection to the database.
Then I print the first line in the CSV file.
Then I iterate through the data.
In the end, this produces a page you can save as *.csv for import.
Ugly code, but it works for me. :-) I'd be open to criticism and better ways
to what I'm doing here. This was for a tool my wife and I use to keep track
of addresses, and a great example of code-as-you-go. Messy but fun.
Something like:
<?
function csv_td($foo) {
if ($foo!='')
{echo "$foo\t"; }
else
{ echo "\t"; }; };
$query = "select
last,
first,
address,
city,
state,
zip,
from my_table";
RSVP_connect() // This is my custom connection function
// Use one of your own. :-)
or die ("Cannot connect to server.");
echo "<pre>"; // this bit just makes some headers
csv_td("first");
csv_td("last");
csv_td("address");
csv_td("city");
csv_td("state");
csv_td("zip");
while ($row = mysql_fetch_row ($result))
{
for ($i = 0; $i < mysql_num_fields ($result); $i=$i+7)
{
csv_td($row[$i+2]); //first
csv_td($row[$i+1]); //last
csv_td($row[$i+3]); //address
csv_td($row[$i+4]); //city
csv_td($row[$i+5]); //state
csv_td($row[$i+6]); //zip
echo "\n";
}
};
echo "</pre>";
mysql_free_result ($result);
?>
Hope you're not disappointed. :-)
- Joe <http://artlung.com/>
--
Joe Crawford |||||||||||||| mailto:jcrawford at avencom.com
|||||||||||||||||||||||| http://www.avencom.com
||||||||||||||||||||||||||| Avencom: Set Your Sites Higher
More information about the thelist
mailing list