Jump to content

Recommended Posts

<?php
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="export.csv"');
$hostname = "localhost";
$username = "root";
$password = "98989lol";
$dbname = "licensinginformation";

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");
$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

$query = "SELECT * FROM invoiceid";
$Result = mysql_query($query) or DIE("Could not query");

while ($row=mysql_fetch_array($Result)){
$customeridlist[]= $row['customerid'];
}
foreach ($customeridlist as $key => $customer){
$query2 = "SELECT * FROM invoiceid WHERE customerid ='$customer'";
$Result2 = mysql_query($query2) or DIE("Could not query2");
$pidcounter=0;
while ($row2=mysql_fetch_array($Result2)){
	$invoicenumlist[]= $row2['invoicenum'];
	$numoflicenses[] = $row2['numoflicenses'];
}
foreach ($invoicenumlist as $key1 => $value){
	$query3 = "SELECT * FROM productid WHERE invoicenum='$value'";
	$Result3=mysql_query($query3) or DIE("Could not query3");
	while ($row3=mysql_fetch_array($Result3)){
		$productidlist[]= $row3['productid'];
		if ($row3['productid']!= ""){
			$pidcounter=$pidcounter+1;
		}
	}
}
$counter=0;
$str="";
$size = count($invoicenumlist);
while ($size<3){
	$invoicenumlist[] = "";
	$size=$size + 1;
}
foreach ($numoflicenses as $key2 => $value2){
	$counter = $counter + $value;
}
$total = $counter - $pidcounter;
$str.= $customer.", ".$counter.", ".$total.", ".$invoicenumlist[0].", ".$invoicenumlist[1].", ".$invoicenumlist[2];
foreach ($productidlist as $key3 => $value3){
	$str.=", ".$value;
}
$str.= "\n";
unset($invoicenumlist);
unset($productidlist);
unset($numoflicenses);
echo $str;

}


// Open file export.csv.
$f = fopen ('export.csv','w');

// Put all values from $out to export.csv. 
fputs($f, $str);
fclose($f);


?>

 

Can someone please tell me whats wrong with this script and why it doesn't work. I keep on getting the following errors:

 

<br />

<b>Warning</b>:  Cannot use a scalar value as an array in <b>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\InputMaintainance\reportdata1.php</b> on line <b>37</b><br />

<br />

<b>Warning</b>:  Cannot use a scalar value as an array in <b>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\InputMaintainance\reportdata1.php</b> on line <b>58</b><br />

<br />

<b>Warning</b>:  Invalid argument supplied for foreach() in <b>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\InputMaintainance\reportdata1.php</b> on line <b>61</b><br />

<br />

<b>Notice</b>:  Undefined variable: total in <b>C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\InputMaintainance\reportdata1.php</b> on line <b>65</b><br />

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.