RE: [PHP] exporting data by field size

From: Date: Mon, 21 Apr 2003 00:49:24 +0000
Subject: RE: [PHP] exporting data by field size
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144579@lists.php.net to get a copy of this message
On 20-Apr-2003 M.E. Suliman wrote: > Hi > > Thanks to Don and Peter for their previous replies. I've tried both your > suggestions. I can't seem to get it right, even using sprintf(). The > problem that I am having is that e.g. the National_Id field is > VARCHAR(20) > and the actual ID number is 13 characters. The data of the next column > should only start after the 20 spaces (i.e. 13 for the ID and 7 blank). > The > other difficulty is that the field size for the rest of the columns are > not > the same. > > Any help or suggestions would be appreciated on how I could overcome > this. > Do your query LIMIT 1. Loop on each field with $o=mysql_fetch_field() building a format string: $fmt .='%-' .%o->max_length .'s'; Free your result. Repeat the query (with out the LIMIT) and output to file: fwrite($f, sprintf("$fmt\n", $row)); Regards, -- Don Read dread@texas.net -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it.

« previous php.general (#144579) next »