2 scripts in 1 script verwerken

Status
Niet open voor verdere reacties.

Earthfighter

Gebruiker
Lid geworden
5 sep 2012
Berichten
28
Hallo iedereen die dit leest,

Ik heb een vraag.
Op dit moment heb ik 2 scripts die bijna hetzelfde doen. De ene laat een tabel zien (webpage) van de klanten die deze maand jarig zijn en de andere script exporteerd deze gegevens naar excel. Ze werken goed maar nu komt het lastige, tenminste ik heb het nog nooit gedaan. Je kan uit een dropdown menu de maand selecteren.

Na submit te hebben gedrukt krijg je de hele lijst te zien van alle jarige. Onder de tabel wil ik een knop waarop staat. Exporteer naar excel. Dit werkt nog niet zoals ik wil. Ik krijg de tabel te zien met de knop zoals ik het wil. Maar als ik op de knop druk dan loopt hij het hele script weer langs en weet hij niet meer welke maand ik had ingevuld. (missende variabel) Hoe kan ik dit oplossen?

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html>
<head>
<title>oefening2_2</title>
</head>
<body>

<?php

if(isset ($_POST["button"])) {
$month = $_POST["month"];

}


$dsn = "Goldmine";
$user = "";
$pass = "";
   $conn  = odbc_connect("$dsn","$user","$pass");
if (!$conn)
  {exit("Connection Failed: " . $conn);}

  
$query = 
"
SELECT CONTACT1.COMPANY, CONTACT1.TITLE, CONTACT1.CONTACT, CONTACT1.LASTNAME, CONTACT1.PHONE1, CONVERT(char(6), CONTACT2.UDOB, 6) AS BIRTHDAY
FROM CONTACT1 LEFT JOIN CONTACT2 ON CONTACT1.ACCOUNTNO = CONTACT2.ACCOUNTNO
WHERE CONTACT2.UDOB IS NOT NULL AND MONTH(CONTACT2.UDOB)='$month'
ORDER BY BIRTHDAY ASC
 ";

$result= odbc_exec($conn, $query);

 echo "<table border='1'>
<tr>
    
    <th>Company</th>
	<th>Tittle</th>
	<th>Contact</th>
	<th>Lastname</th>
	<th>Cellphonenumber</th>
	<th>Birthday</th>
</tr>";

while(odbc_fetch_row($result)) {
   echo "<tr>";
   echo "<td>" .odbc_result($result,1). "</td>";
   echo "<td>" .odbc_result($result,2). "</td>";
   echo "<td>" .odbc_result($result,3). "</td>";
   echo "<td>" .odbc_result($result,4). "</td>";
   echo "<td>" .odbc_result($result,5). "</td>";
   echo "<td>" .odbc_result($result,6). "</td>"; 
   echo "</tr>";
   }

  echo "</table>";

echo  '
  <form method="GET" enctype="multipart/form-data">
   <div><label><input value="OK" type="submit"/></label></div>
  </form>
  ';

  if( $_SERVER["REQUEST_METHOD"] == 'GET' )
{
$query2 = 
"SELECT CONTACT1.COMPANY, CONTACT1.TITLE, CONTACT1.CONTACT, CONTACT1.LASTNAME, CONTACT1.PHONE1, CONVERT(char(6), CONTACT2.UDOB, 6) AS BIRTHDAY
FROM CONTACT1 LEFT JOIN CONTACT2 ON CONTACT1.ACCOUNTNO = CONTACT2.ACCOUNTNO
WHERE CONTACT2.UDOB IS NOT NULL AND MONTH(CONTACT2.UDOB)='$month'
ORDER BY BIRTHDAY ASC
 ";
 
$result2= odbc_exec($conn, $query2);

    function xlsBOF()
    {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
    return;
    }
	
    function xlsEOF()
    {
    echo pack("ss", 0x0A, 0x00);
    return;
    }
	
    function xlsWriteNumber($Row, $Col, $Value)
    {
    echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    echo pack("d", $Value);
    return;
    }
	
    function xlsWriteLabel($Row, $Col, $Value )
    {
    $L = strlen($Value);
    echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    echo $Value;
    return;
    }
    
	header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");;
    header("Content-Disposition: attachment;filename=list.xls");
    header("Content-Transfer-Encoding: binary ");
    
	/*xlsBOF();   // begin Excel stream 
xlsWriteLabel(0,0,"This is a label");  // write a label in A1, use for dates too 
xlsWriteNumber(0,1,9999);  // write a number B1 
xlsEOF(); // close the stream */
	
	xlsBOF(); // begin Excel stream 
     
    xlsWriteLabel(0,0,"COMPANY");  // write a label in A1, use for dates too 
    xlsWriteLabel(0,1,"TITLE");
    xlsWriteLabel(0,2,"CONTACT");
	xlsWriteLabel(0,3,"LASTNAME");
	xlsWriteLabel(0,4,"PHONE1");
	xlsWriteLabel(0,5,"BIRTHDAY");
	/*xlsWriteLabel(0,5,"UDOB");*/
    
	$xlsRow = 1;
    
	while($row=odbc_fetch_array($result2)){
    xlsWriteLabel($xlsRow,0,$row['COMPANY']);
    xlsWriteLabel($xlsRow,1,$row['TITLE']);
    xlsWriteLabel($xlsRow,2,$row['CONTACT']);
    xlsWriteLabel($xlsRow,3,$row['LASTNAME']);
	xlsWriteLabel($xlsRow,4,$row['PHONE1']);
	xlsWriteLabel($xlsRow,5,$row['BIRTHDAY']);
	/*xlsWriteLabel($xlsRow,5,$row['UDOB']);*/
	$xlsRow++;
    }
	
    xlsEOF(); //close the stream
 } 
  ?>
 
Laatst bewerkt:
Hallo iedereen die dit leest,
.....
Maar als ik op de knop druk dan loopt hij het hele script weer langs en weet hij niet meer welke maand ik had ingevuld. (missende variabel) Hoe kan ik dit oplossen?

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html>
<head>
<title>oefening2_2</title>
</head>
<body>

<?php

if(isset ($_POST["button"])) {
$month = $_POST["month"];

}


$dsn = "Goldmine";
$user = "";
$pass = "";
   $conn  = odbc_connect("$dsn","$user","$pass");
if (!$conn)
  {exit("Connection Failed: " . $conn);}

  
$query = 
"
SELECT CONTACT1.COMPANY, CONTACT1.TITLE, CONTACT1.CONTACT, CONTACT1.LASTNAME, CONTACT1.PHONE1, CONVERT(char(6), CONTACT2.UDOB, 6) AS BIRTHDAY
FROM CONTACT1 LEFT JOIN CONTACT2 ON CONTACT1.ACCOUNTNO = CONTACT2.ACCOUNTNO
WHERE CONTACT2.UDOB IS NOT NULL AND MONTH(CONTACT2.UDOB)='$month'
ORDER BY BIRTHDAY ASC
 ";

$result= odbc_exec($conn, $query);

 echo "<table border='1'>
<tr>
    
    <th>Company</th>
	<th>Tittle</th>
	<th>Contact</th>
	<th>Lastname</th>
	<th>Cellphonenumber</th>
	<th>Birthday</th>
</tr>";

while(odbc_fetch_row($result)) {
   echo "<tr>";
   echo "<td>" .odbc_result($result,1). "</td>";
   echo "<td>" .odbc_result($result,2). "</td>";
   echo "<td>" .odbc_result($result,3). "</td>";
   echo "<td>" .odbc_result($result,4). "</td>";
   echo "<td>" .odbc_result($result,5). "</td>";
   echo "<td>" .odbc_result($result,6). "</td>"; 
   echo "</tr>";
   }

  echo "</table>";

echo  '
  <form method="GET" enctype="multipart/form-data">
   <div><label><input value="OK" type="submit"/></label></div>
  </form>
  ';

  if( $_SERVER["REQUEST_METHOD"] == 'GET' )
{
$query2 = 
"SELECT CONTACT1.COMPANY, CONTACT1.TITLE, CONTACT1.CONTACT, CONTACT1.LASTNAME, CONTACT1.PHONE1, CONVERT(char(6), CONTACT2.UDOB, 6) AS BIRTHDAY
FROM CONTACT1 LEFT JOIN CONTACT2 ON CONTACT1.ACCOUNTNO = CONTACT2.ACCOUNTNO
WHERE CONTACT2.UDOB IS NOT NULL AND MONTH(CONTACT2.UDOB)='$month'
ORDER BY BIRTHDAY ASC
 ";
 
$result2= odbc_exec($conn, $query2);

    function xlsBOF()
    {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
    return;
    }
	
    function xlsEOF()
    {
    echo pack("ss", 0x0A, 0x00);
    return;
    }
	
    function xlsWriteNumber($Row, $Col, $Value)
    {
    echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    echo pack("d", $Value);
    return;
    }
	
    function xlsWriteLabel($Row, $Col, $Value )
    {
    $L = strlen($Value);
    echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    echo $Value;
    return;
    }
    
	header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");;
    header("Content-Disposition: attachment;filename=list.xls");
    header("Content-Transfer-Encoding: binary ");
    
	/*xlsBOF();   // begin Excel stream 
xlsWriteLabel(0,0,"This is a label");  // write a label in A1, use for dates too 
xlsWriteNumber(0,1,9999);  // write a number B1 
xlsEOF(); // close the stream */
	
	xlsBOF(); // begin Excel stream 
     
    xlsWriteLabel(0,0,"COMPANY");  // write a label in A1, use for dates too 
    xlsWriteLabel(0,1,"TITLE");
    xlsWriteLabel(0,2,"CONTACT");
	xlsWriteLabel(0,3,"LASTNAME");
	xlsWriteLabel(0,4,"PHONE1");
	xlsWriteLabel(0,5,"BIRTHDAY");
	/*xlsWriteLabel(0,5,"UDOB");*/
    
	$xlsRow = 1;
    
	while($row=odbc_fetch_array($result2)){
    xlsWriteLabel($xlsRow,0,$row['COMPANY']);
    xlsWriteLabel($xlsRow,1,$row['TITLE']);
    xlsWriteLabel($xlsRow,2,$row['CONTACT']);
    xlsWriteLabel($xlsRow,3,$row['LASTNAME']);
	xlsWriteLabel($xlsRow,4,$row['PHONE1']);
	xlsWriteLabel($xlsRow,5,$row['BIRTHDAY']);
	/*xlsWriteLabel($xlsRow,5,$row['UDOB']);*/
	$xlsRow++;
    }
	
    xlsEOF(); //close the stream
 } 
  ?>

Eerst en vooral zal dit veranderen


PHP:
....
if(isset ($_POST["button"])) {
$month = $_POST["month"];

}
....
// BEKIJK INLCLUDE 
//VERVOLGENS ZAL JE MERKEN DAT get EN POST NIET HET ZELFDE ZIJN 
//TYP VERVOLGENS ONDERSTAANDE ALS TEST DUS VERDER HOOR IK HET WEL OF HET LUKTE 
PRINT_R($_POST);
PRINT_R($_get);
PRINT_R($_session);

....


echo  '
  <form method="GET" enctype="multipart/form-data">
   <div><label><input value="OK" type="submit"/></label></div>
  </form>
  ';
.....
 
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan