Jump to content

passing an argument in a php script to download info into excel not working


ETSoft

Recommended Posts

Hi,

 

the downlad script is working but when i try to pass an argument it is ignored.

 

$firma= $_GET['argument1'];

    function Database_Connect()
        {
            $Host="localhost";
            $Username="";
            $Password="";
            $dbName="";
            $Error_Message="";


            @$Connector=new mysqli($Host,$Username,$Password,$dbName);

            if(mysqli_connect_errno())
            {
            $Error_Message="<br/><br/><div class='alert alert-danger'><i class='icon-remove-circle'></i>Sorry System '".$dbName."' Database Connection Failed to Initiate on this: ".$Host." Server, Username: ".$Username.".Please try again Later</div>";
            die($Error_Message);
            exit();
            }
            else
            {
            return $Connector;
            }

        }

    function MySql_Excel_Exporter()
        {
	
        $Excel_File = $firma . "-Export_Planning_".date("Y-m-d").".xls";
        $Separator="\t";

        /* Header info settings */
        header("Content-Type: application/xls");
        header("Content-Disposition: attachment; filename=".$Excel_File."");
        header("Pragma: no-cache");
        header("Expires: 0");

        $MySqli=Database_Connect();
       
        $Sql="SELECT  * from table  Where Responsibility ='". $firma ."'order by Activityid";
        $Query=$MySqli->prepare($Sql);
        $Query->execute();
        $Query->bind_result($....);

       print(trim("Activiteit"."".$Separator.""."O"."".$Separator.""."P"."".$Separator.""."S"."".$Separator.""."K"."".$Separator.""."LA"));
              print "\n";

        while($Fetch=$Query->fetch())
            {           
              $Schema_Insert = "";
              /* HERE I ACCEPT IF THERE IS A BETTER WAY OF JUST GETTING THE VALUES IN A FORM OF DYNAMIC WAY
              OF REFFERING COLUMS AS IN THE ORIGINAL CODE JUST USED LOOP TO GET COLUMNS,
              BUT AS I FDIDNT KNOW HOW TO DO THAT AND SO I USED WHAT I KNOW THE bind_result()
              AND JUST ASSIGN THEM TO $Schema_Insert FOR EXCEL FORMATING
              */
              $Schema_Insert =$A."".$Separator."".$Ac."".$Separator."".$p."".$Separator."".$s."".$Separator."".$k."".$Separator."".$la."".$Separator."";
              $Schema_Insert = str_replace($Separator."$", "", $Schema_Insert);
              $Schema_Insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $Schema_Insert);
              $Schema_Insert .= "\t";
              print(trim($Schema_Insert));
              print "\n";

            }
        $Query->close();
        }
	 
        MySql_Excel_Exporter();
?>

(sensitive information is removed).

 

Without the $firma variable it is working.

Could someone help me on this one?

 

Thanks in advance

 

Erwin

 

Link to comment
Share on other sites

You really make hard work of defining strings with all that concatenation and adding empty strings between everything. You could have just written

$Schema_Insert ="$A\t$Ac\t$p\t$s\t$k\t$la";

eg

$A  = 'xyz';
$Ac = 'abc';
$p  = 'mno';
$s  = 123;
$k  = 456;
$la = 'LA';

$Schema_Insert ="$A\t$Ac\t$p\t$s\t$k\t$la";

echo '<pre>';
echo $Schema_Insert;         //--> xyz     abc	  mno 	 123 	456 	LA
echo '</pre>';

 

Link to comment
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.