hi

i'm pulling multiple rows of data from my database to display in a csv document but every row it displays is the same as the first row. appreciate the help.

<?php
	session_start();
	
	include 'include.php';
	
	connect_db();
	
    $filename = date("Ymd")."_summary.csv";
    header("Content-type: application/csv");
    header("Content-Disposition: attachment; filename=$filename");
	$date = date("Y/m/d");
	
	$sql = "SELECT * FROM sales WHERE datePro = '".$date."'";
	$sumres = mysql_query($sql);
	
	if ($_SESSION['summary'] = 'yes')
	{
	$num = mysql_num_rows($sumres);
	$arr = mysql_fetch_array($sumres);
	
	
    $field_arr = array('Customer Name','Quantity Bought','Amount Paid','Mode of Payment','Salespersons ID', 'Date of Sale');
    foreach($field_arr as $val)
        rtrim_csv_out($val);
    echo "\n";

    for($i=1; $i<=$num; $i++)
    {
        rtrim_csv_out( $arr['custName'] );
        rtrim_csv_out( $arr['qty'] );
        rtrim_csv_out( $arr['amntPaid'] );
		rtrim_csv_out( $arr['mode'] );
		rtrim_csv_out( $arr['empID'] );
		rtrim_csv_out( $arr['datePro'] );
       
        echo "\n";
    }
	}else{
	
		echo "No sales Made today";
	}

    function rtrim_csv_out($str)
    {
        echo '"'.rtrim(str_replace('"','""',$str)).'",';
    }
?>

Line 20 needs to go to line 30. Currently you get 1 row as array (line 20) ask how many rows there are (line 19) and the for... loop loops that many times but never gets any new data from the database.
The flow of this kind of operation is to do a query, test for error(s), ask how many results there are and start a loop (for $=0; $i < number_of_results...) and inside this loop you get the data (mysql_fetch_array).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.