Welcome visitor
* Login
* Register
It is currently March 26th, 2019, 6:30 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Server Side » PHP



Post new topic Reply to topic  [ 4 posts ] 
Author Message
  table look like using fopen
PostPosted: February 27th, 2009, 4:12 am 

Posts: 46
hi, i need some help here. Im sending info from MySQL to a .txt document, and of curse its not very legible. Is there any function to give format to what is written onthe txt file?


Top
 Profile  
 
  Re: table look like using fopen
PostPosted: February 27th, 2009, 4:39 am 

Posts: 46
sorry, i forgot to add something of my code to give you an idea of what im doing
//connect to MySQL

$txt = 'output.txt';
$write = "id Name age color\n";

$handle = fopen($txt, 'atb');
fwrite($handle, $write);
fclose($handle);

//then i do the query to MySQL

while ($db_row=mysql_fetch_array($db_table)){
    extract($db_row);
    $write = $id . $name . $age . $color . "\n";
    $handle = fopen($txt, 'atb');
    fwrite($handle, $write); }
hope this helps to figure out what im asking for. Thanks in advanced for any help.


Top
 Profile  
 
  Re: table look like using fopen
PostPosted: February 27th, 2009, 6:11 am 
User avatar

Posts: 81
//a little stuff to make the headers fit a size, of curse you can resize the 'columns'      
$id = "id";
$id = str_pad($id, 5, " ");
$name = "Name";
$name = str_pad($name, 12, " ", STR_PAD_BOTH);
$age = "age";
$age = str_pad($age, 5, " ",STR_PAD_LEFT);
$color = "color";
$color = str_pad($color, 12, " ", STR_PAD_BOTH); 

$write = $id . $name . $age . $color . "\n";

//the next stays the same
$handle = fopen($txt, 'atb');
fwrite($handle, $write);
fclose($handle);

//then apply the same style to the content
//i made a little change on the name, you can do what you want
while ($db_row=mysql_fetch_array($db_table)){
        extract($db_row);
        $id = str_pad($id, 5, " ");
        $name = str_pad($name, 12, " ");
        $age = str_pad($age, 5, " ",STR_PAD_LEFT);
        $color = str_pad($color, 12, " ", STR_PAD_BOTH); 
        $somecontent = $id . $name . $age . $color . "\n";

//the rest is the same
hope this gives ya an idea of what u can do and how to do it, have fun


Top
 Profile  
 
  Re: table look like using fopen
PostPosted: February 27th, 2009, 6:17 am 

Posts: 46
superb man! I really appreciate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

FORUMS » Server Side » PHP


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron