SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP ON Centering the exported data using php in text

    Hello everyone,
    I have managed to come with code that is exporting data from mysql table into text . The code is below. But my problems are follows the exported data is not properly aligned becuase it text. So how can achieve??

    Second. I able to extract data from table but, I do not want it exporting column or field names. I just want data. How can I solve it???

    Your help will highly appreaciated.

    <?php
    include ('../conn.php');

    $select = "SELECT * FROM payments";
    $export = mysql_query($select);
    $fields = mysql_num_fields($export);

    for ($i = 0; $i < $fields; $i++) {
    $header .= mysql_field_name($export, $i) . "\t";
    }



    while($row = mysql_fetch_row($export)) {
    $line = '';
    foreach($row as $value) {
    if ((!isset($value)) OR ($value == "")) {
    $value = "\t";
    } else {
    $value = str_replace('"', '""', $value);
    $value = $value . ';' . "\t";
    }
    $line .= $value;
    }
    $data .= trim($line)."\n";
    }
    $data = str_replace("\r","",$data);
    if ($data == "") {
    $data = "\n(0) Records Found!\n";
    }
    header("Content-type: application/x-msdownload");
    header("Content-Disposition: attachment; filename=TRVP.txt");
    header("Pragma: no-cache");
    header("Expires: 0");
    print "$header\n$data";

    ?>

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,751
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you trying to export data into a comma seperated value file? If so don't do this with PHP, use mysqldump.
    Also, if you have MySQL 5.1 beta, you can take advantage of the CSV storage engine.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •