DeepakJ Posted August 1, 2007 Share Posted August 1, 2007 <?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 /> Quote Link to comment https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/ Share on other sites More sharing options...
studgate Posted August 1, 2007 Share Posted August 1, 2007 Is this the reportdata1.php file???? Quote Link to comment https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/#findComment-313058 Share on other sites More sharing options...
DeepakJ Posted August 1, 2007 Author Share Posted August 1, 2007 yes Quote Link to comment https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/#findComment-313093 Share on other sites More sharing options...
DeepakJ Posted August 1, 2007 Author Share Posted August 1, 2007 wait no it isn't Quote Link to comment https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/#findComment-313094 Share on other sites More sharing options...
DeepakJ Posted August 1, 2007 Author Share Posted August 1, 2007 The errors are gone now but the values it displays are off Quote Link to comment https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/#findComment-313097 Share on other sites More sharing options...
DeepakJ Posted August 1, 2007 Author Share Posted August 1, 2007 YES IT WORkS :D::D:: Quote Link to comment https://forums.phpfreaks.com/topic/62893-solved-help-fix-this-script-please/#findComment-313098 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.