0

Hello there,

         colud you please tell me that how can i generate html into csv, actually it display all tr and td into csv file, here i have share my code
<?php
/*include("wp-config.php");
include("wp-app.php");
include("wp-active.php");
include("wp-settings.php");*/
//include("index.php");
include("wp-load.php");
include("wp-includes/template-loader.php");

header ("Expires: Mon, 12 Aug 1988 23:30:00 GMT");
header ("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header ("Pragma: no-cache");
header ("Content-type: text/csv; charset=UTF-8");
header ("Content-Disposition: attachment; filename=report.csv");
header ("Content-Description: Generated Report" );

    /* wordpress
    $wpdb->hide_errors();
                @set_time_limit(0);
                @ob_clean();
                header( 'Content-Type: text/csv; charset=UTF-8' );
                header( 'Content-Disposition: attachment; filename=woocommerce-product-export.csv' );
                header( 'Pragma: no-cache' );
                header( 'Expires: 0' );
                $fp = fopen('php://output', 'w');*/
?>
<?php
 //global $wpdb;



$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="patsyjane_db"; // Database name
//$tbl_name="wp_posts"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//$id=$_POST['id'];

//$sql="select * from wp_posts where post_type='".$value."'";
//$res=mysql_query($sql);
//echo $total_rows=mysql_num_rows($res)."<br>";

//$sql="SELECT * FROM wp_posts where id='739'";
//$result=mysql_query($sql);


?>
<?php echo "<html><body><table>\n\n"; ?>
<?php $display.='<th>'.post_title.'</th>'?>
<th>post_name</th>
<th>ID</th>
<th>post_excerpt</th>
<th>post_content</th>
<th>post_status</th>
<th>menu_order</th>
<th>post_date</th>
<th>post_parent</th>
<th>comment_status</th>
<th>sku</th>
<th>downloadable</th>
<th>virtual</th>
<th>visibility</th>
<th>stock</th>
<th>stock_status</th>
<th>backorders</th>
<th>manage_stock</th>
<th>regular_price</th>
<th>sale_price</th>
<th>weight</th>
<th>length</th>
<th>width</th>
<th>height</th>
<th>tax_status</th>
<th>tax_class</th>
<th>upsell_ids</th>
<th>crosssell_ids</th>
<th>featured</th>
<th>sale_price_dates_from</th>
<th>sale_price_dates_to</th>
<th>file_path</th>
<th>download_limit</th>
<th>download_expiry</th>
<th>product_url</th>
<th>button_text</th>
<th>images</th>
<th>tax:product_type</th>
<th>tax:product_cat</th>
<th>tax:product_tag</th>
<th>tax:product_shipping_class</th>
<th>meta:total_sales</th>
<th>meta:video_url</th>
<th>meta:product_info</th>
<th>meta:delivery</th>
<th>meta:returns</th>
<th>meta:varid_47</th>
<th>meta:varid_94</th>
<th>meta:varid_262</th>
<th>meta:varid</th>
<th>meta:varid_357</th>
<th>meta:varid_48</th>
<th>meta:varid_246</th>
<th>meta:varid_290</th>
<th>meta:varid_99</th>
<th>meta:varid_272</th>

<th>attribute:pa_size</th>
<th>attribute_data:pa_size</th>
<th>attribute_default:pa_size</th>
<th>attribute:pa_colour</th>
<th>attribute_data:pa_colour</th>
<th>attribute_default:pa_colour</th>
<th>attribute:pa_brand</th>
<th>attribute_data:pa_brand</th>
<th>attribute_default:pa_brand</th>
<th>attribute:pa_la-idol-sizing</th>
<th>attribute_data:pa_la-idol-sizing</th>
<th>attribute_default:pa_la-idol-sizing</th>
<th>attribute:pa_skirts</th>
<th>attribute_data:pa_skirts</th>
<th>attribute_default:pa_skirts</th>
<th>attribute:pa_true-religion-sizing</th>
<th>attribute_data:pa_true-religion-sizing</th>
<th>attribute_default:pa_true-religion-sizing</th>
<th>attribute:pa_betty-basics-colours</th>
<th>attribute_data:pa_betty-basics-colours</th>
<th>attribute_default:pa_betty-basics-colours</th>
<th>attribute:pa_shoe-size</th>
<th>attribute_data:pa_shoe-size</th>
<th>attribute_default:pa_shoe-size</th>
<th>attribute:pa_shoe-colours</th>
<th>attribute_data:pa_shoe-colours</th>
<th>attribute_default:pa_shoe-colours</th>
<th>attribute:pa_metallic</th>
<th>attribute_data:pa_metallic</th>
<th>attribute_default:pa_metallic</th>
<th>attribute:pa_color</th>
<th>attribute_data:pa_color</th>
<th>attribute_default:pa_color</th>
<?php
$value = "product";
$sql = "SELECT * FROM wp_posts where post_type='".$value."'";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
  $post_title = $row['post_title'];
  $post_name=$row['post_name'];
  $id=$row['ID'];
  $post_excerpt=$row['post_excerpt'];
  $post_content=$row['post_content'];
  $post_status=$row['post_status'];
  $menu_order=$row['menu_order'];
  $post_date=$row['post_date'];
  $post_parent=$row['post_parent'];
  $comment_status=$row['comment_status'];

$value="_sku";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$sku= $row['3'];

$value="_downloadable";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$downloadable= $row['3'];

$value="_virtual";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$virtual= $row['3'];

$value="_visibility";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$visibility= $row['3'];

$value="_stock";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$stock= $row['3'];

$value="_stock_status";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$stock_status= $row['3'];

$value="_backorders";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$backorders= $row['3'];

$value="_manage_stock";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$manage_stock= $row['3'];

$value="_regular_price";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$regular_price= $row['3'];

$value="_sale_price";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$sale_price= $row['3'];

$value="_weight";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$weight= $row['3'];

$value="_length";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$length= $row['3'];

$value="_width";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$width= $row['3'];


$value="_height";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$height= $row['3'];


$value="_tax_status";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$tax_status= $row['3'];


$value="_tax_class";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$tax_class= $row['3'];

$value="_upsell_ids";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$upsell_ids= $row['3'];


$value="_crosssell_ids";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$crosssell_ids= $row['3'];


$value="_featured";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$featured= $row['3'];


$value="_sale_price_dates_from";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$sale_price_dates_from= $row['3'];


$value="_sale_price_dates_to";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$sale_price_dates_to= $row['3'];

$value="_file_path";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$file_path= $row['3'];


$value="_download_limit";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$download_limit= $row['3'];

$value="_download_expiry";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$download_expiry= $row['3'];

$value="_product_url";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$product_url= $row['3'];

$value="_button_text";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$button_text= $row['3'];

$value="total_sales";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$total_sales= $row['3'];

$value="video_url";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$video_url= $row['3'];

$value="product_info";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$product_info= $row['3'];

$value="delivery";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$delivery= $row['3'];


$value="returns";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$returns= $row['3'];


$value="varid_47";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_47= $row['3'];


$value="varid_94";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_94= $row['3'];



$value="varid_262";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_262= $row['3'];


$value="varid";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid= $row['3'];


$value="varid_357";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_357= $row['3'];


$value="varid_48";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_48= $row['3'];


$value="varid_246";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_246= $row['3'];


$value="varid_290";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_290= $row['3'];


$value="varid_99";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_99= $row['3'];


$value="varid_272";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$varid_272= $row['3'];


$value="attribute_pa_colour";
$sql="SELECT * FROM wp_postmeta where post_id='".$id."' && meta_key='".$value."'";
$sql=mysql_query($sql);
$row=mysql_fetch_row($sql);
$attribute_pa_colour= $row['3'];

//echo $id."<br>";
/*attributes*/
/*
$sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
$sql_att=mysql_query($sql_att);
while($att=mysql_fetch_array($sql_att))
{
   $taxo_id = $att['term_taxonomy_id']; 

    $value="pa_colour";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $pa_colour= $row['1'];

    $result="SELECT * FROM wp_terms WHERE term_id='".$term_id."' ";
    $result=mysql_query($result);
    $row=mysql_fetch_row($result);
    echo $name= $row['1'];

     $value="pa_size";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $term_id= $row['1'];

    $result="SELECT * FROM wp_terms WHERE term_id='".$term_id."' ";
    $result=mysql_query($result);
    $row=mysql_fetch_row($result);
    echo $name= $row['1'];

}*/


 ?> <tr>

        <td><?php echo $post_title;?></td>
        <td><?php echo $post_name;?></td>
        <td><?php echo $id;?></td>
        <td><?php echo substr($post_excerpt,0,10);?></td>
        <td><?php echo substr($post_content,0,10);?></td>
        <td><?php echo $post_status;?></td>
        <td><?php echo $menu_order;?></td>
        <td><?php echo $post_date;?></td>
        <td><?php echo $post_parent;?></td>
        <td><?php echo $comment_status;?></td>
        <td><?php echo $sku;?></td>
        <td><?php echo $downloadable;?></td>
        <td><?php echo $virtual;?></td>
        <td><?php echo $visibility;?></td>
        <td><?php echo $stock;?></td>
        <td><?php echo $stock_status;?></td>
        <td><?php echo $backorders;?></td>
        <td><?php echo $manage_stock;?></td>
        <td><?php echo $regular_price;?></td>
        <td><?php echo $sale_price;?></td>
        <td><?php echo $weight;?></td>
        <td><?php echo $length;?></td>
        <td><?php echo $width;?></td>
        <td><?php echo $height;?></td>
        <td><?php echo $tax_status;?></td>
        <td><?php echo $tax_class;?></td>
        <td><?php echo $upsell_ids;?></td>
        <td><?php echo $crosssell_ids;?></td>
        <td><?php echo $featured;?></td>
        <td><?php echo $sale_price_dates_from;?></td>
        <td><?php echo $sale_price_dates_to;?></td>
        <td><?php echo $file_path;?></td>
        <td><?php echo $download_limit;?></td>
        <td><?php echo $download_expiry;?></td>
        <td><?php echo $product_url;?></td>
        <td><?php echo $button_text;?></td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td><?php echo $total_sales;?></td>
        <td><?php echo $video_url;?></td>
        <td><?php echo substr($product_info,0,10);?></td>
        <td><?php echo $delivery;?></td>
        <td><?php echo $returns;?></td>
        <td><?php echo $varid_47;?></td>
        <td><?php echo $varid_94;?></td>
        <td><?php echo $varid_262;?></td>
        <td><?php echo $varid;?></td>
        <td><?php echo $varid_357;?></td>
        <td><?php echo $varid_48;?></td>
        <td><?php echo $varid_246;?></td>
        <td><?php echo $varid_290;?></td>
        <td><?php echo $varid_99;?></td>
        <td><?php echo $varid_272;?></td>


        <td>
        <?php        
        $sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
    $sql_att=mysql_query($sql_att);
    while($att=mysql_fetch_array($sql_att))
    {
    $taxo_id = $att['term_taxonomy_id']; 
    $value="pa_size";
    $res1="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res1=mysql_query($res1);
    $row=mysql_fetch_row($res1);
    $term_id= $row['1'];

    $result2="SELECT * FROM wp_terms WHERE term_id='".$term_id."' ";
    $result2=mysql_query($result2);
    $row=mysql_fetch_row($result2);
    $pa_sizess= $row['1'];
    if($pa_sizess)
    echo $pa_sizess." | ";

    }
        ?></td>
        <td> </td>
        <td> </td>
        <td>
<?php        
   $sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
    $sql_att=mysql_query($sql_att);
    while($att=mysql_fetch_array($sql_att))
    {
    $taxo_id = $att['term_taxonomy_id']; 

    $value="pa_colour";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $pa_colour= $row['1'];

    $result1="SELECT * FROM wp_terms WHERE term_id='".$pa_colour."' ";
    $result1=mysql_query($result1);
    $row=mysql_fetch_row($result1);
     $pa_colorss= $row['1'];
    if($pa_colorss)
     echo $pa_colorss." | ";
}
        ?></td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>

    <td>
<?php        
   $sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
    $sql_att=mysql_query($sql_att);
    while($att=mysql_fetch_array($sql_att))
    {
    $taxo_id = $att['term_taxonomy_id']; 

    $value="pa_la-idol-sizing";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $pa_la_idol_sizing = "pa_la-idol-sizing";
    $pa_la_idol_sizing = $row['1'];

    $result1="SELECT * FROM wp_terms WHERE term_id='".$pa_la_idol_sizing."' ";
    $result1=mysql_query($result1);
    $row=mysql_fetch_row($result1);
    $pa_la_idol_sizing= $row['1'];
    if($pa_la_idol_sizing)
    echo $pa_la_idol_sizing." | ";
}
        ?></td>  


        <td> </td>
        <td> </td>


        <td>
<?php        
   $sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
    $sql_att=mysql_query($sql_att);
    while($att=mysql_fetch_array($sql_att))
    {
    $taxo_id = $att['term_taxonomy_id']; 

    $value="pa_skirts";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $pa_skirts= $row['1'];

    $result1="SELECT * FROM wp_terms WHERE term_id='".$pa_skirts."' ";
    $result1=mysql_query($result1);
    $row=mysql_fetch_row($result1);
     $pa_skirts= $row['1'];
    if($pa_skirts)
     echo $pa_skirts." | ";
}
        ?></td>
        <td> </td>
        <td> </td>
        <td>
<?php        
   $sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
    $sql_att=mysql_query($sql_att);
    while($att=mysql_fetch_array($sql_att))
    {
    $taxo_id = $att['term_taxonomy_id']; 

    $value="pa_true-religion-sizing";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $pa_true_religion_sizing="pa_true-religion-sizing";
    $pa_true_religion_sizing= $row['1'];

    $result1="SELECT * FROM wp_terms WHERE term_id='".$pa_true_religion_sizing."' ";
    $result1=mysql_query($result1);
    $row=mysql_fetch_row($result1);
    $pa_true_religion_sizing= $row['1'];
    if($pa_true_religion_sizing)
     echo $pa_true_religion_sizing." | ";
}
        ?></td>
        <td> </td>
        <td> </td>
                <td>
<?php        
   $sql_att="SELECT * FROM wp_term_relationships WHERE object_id='".$id."'";
    $sql_att=mysql_query($sql_att);
    while($att=mysql_fetch_array($sql_att))
    {
    $taxo_id = $att['term_taxonomy_id']; 

    $value="pa_betty-basics-colours";
    $res="SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id='".$taxo_id."' && taxonomy='".$value."'";
    $res=mysql_query($res);
    $row=mysql_fetch_row($res);
    $pa_betty_basics_colours="pa_betty-basics-colours";
    $pa_betty_basics_colours= $row['1'];

    $result1="SELECT * FROM wp_terms WHERE term_id='".$pa_betty_basics_colours."' ";
    $result1=mysql_query($result1);
    $row=mysql_fetch_row($result1);
    $pa_betty_basics_colours= $row['1'];
    if($pa_betty_basics_colours)
     echo $pa_betty_basics_colours." | ";
}
        ?></td>


        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td><?php    

    }   ?>


    </tr><?php


?>
<?php echo "\n</table></body></html>"; 
?>

thanx

2
Contributors
6
Replies
37
Views
4 Years
Discussion Span
Last Post by test.mag
0

Your code is specifically outputing HTML. You can't just slap a CSV content-type at the top of that. You need to update the code and remove the HTML output, and replace it with code that creates CSV output.

You'd usually not generate CSV files like that, though, by echoing the contents like people tend to do with HTML. PHP has CSV generating functions, like fputcsv, that you should use to generate CSV files.

0

thnxxx Atli for your reply,
could you please give me an example, i didn't understand...

0

There is a very good example of how to write CSV files from PHP in the fputcsv documentation. That will show you how to create CSV files. You can then send those files to the client using the readfile function.

Alternatively, you could use a PHP memory or temp stream to avoid having to create an actual file on the server. The documentation for that also has excelent examples.

0

Hello Atli,
thnx for your reply, I am not getting, can you please do changes in my code and then send me back....if possible...

0

No. I'm happy to help you learn how to do this on your own, but I'm not writing the code for you.

What you are asking about is fairly basic. It's something that anybody who has put any amount of effort into learning PHP will know about. - It's not hard to spot the difference between users wanting to learn, and users wanting their code written for them so they don't have to bother with it themselves. The latter doesn't interest us.

0

Thnxx Atli for sugession

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.