Link to home
Start Free TrialLog in
Avatar of lawrence_dev
lawrence_dev

asked on

Need assistance with TXT file export. While Loop has issue.

How do i correctly structure this script to display TXT?    Something is wrong with the while loop.  Apparently I have '  $last = "";  '  in the wrong place....  

Thanks!


$fh = fopen('/home/**********/public_html/ProductFeeds/Bing.txt', 'w');

$sql = 'SELECT * FROM `1MasterFeed_BD_Bing`';
$pdos = $conn100->prepare($sql);
$last = "";
// TRY THE QUERY
try
{
    $pdos->execute();
}
catch(PDOException $exc)
{
    var_dump($exc);
    trigger_error($exc->getMessage(), E_USER_ERROR);
}

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
$num     = $pdos->rowCount();
$num_fmt = number_format($num);
if (!$num)
{
    echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND NO DATA ";
    echo PHP_EOL;
}
else
{
    echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND $num_fmt ROWS OF DATA ";
    echo PHP_EOL;
}

fwrite($fh, "MPID	Title	Brand	MPN	UPC	SKU	ProductURL	Price	Description	ImageURL	Shipping  MerchantCategory  ShippingWeight\n");

		

// ITERATE OVER THE RESULTS SET TO SHOW WHAT WE FOUND
while ($row40 = $pdos->fetch(PDO::FETCH_ASSOC))
{
    
	
	foreach ($row40 as $item) {
        fwrite($fh, $item);
        if ($item != $last)
            fwrite($fh, "\t");
    }
    fwrite($fh, "\n");
		
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial