ไม่ทราบว่า session เก็บ ข้อมูลชุด array ได้หรือเปล่าครับ
ได้ครับลองเข้าไปอ่านบทความตามลิงค์นี้เลยนะครับ
https://www.thaicreate.com/php/php-session-array.html
Date :
2009-05-05 17:00:26
By :
portgasdace
ได้ครับ
Code (PHP)
<?
session_start();
?>
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
$_SESSION["name"] = null;
$_SESSION["name"][] = "I Love ThaiCreate 1";
$_SESSION["name"][] = "I Love ThaiCreate 2";
$_SESSION["name"][] = "I Love ThaiCreate 3";
$_SESSION["name"][] = "I Love ThaiCreate 4";
$_SESSION["name"][] = "I Love ThaiCreate 5";
$_SESSION["name"][] = "I Love ThaiCreate 6";
for($i=0;$i<count($_SESSION["name"]);$i++)
{
echo $_SESSION["name"][$i]."<br>";
}
//==========================================//
echo "<hr>";
$arrVar[] = "I Love ThaiCreate 1";
$arrVar[] = "I Love ThaiCreate 2";
$arrVar[] = "I Love ThaiCreate 3";
$arrVar[] = "I Love ThaiCreate 4";
$arrVar[] = "I Love ThaiCreate 5";
$arrVar[] = "I Love ThaiCreate 6";
$_SESSION["strSession"] = $arrVar;
for($i=0;$i<count($_SESSION["strSession"]);$i++)
{
echo $_SESSION["strSession"][$i]."<br>";
}
?>
</body>
</html>
Ref : PHP Session Array
Date :
2009-05-05 17:01:03
By :
webmaster
Date :
2009-05-05 17:38:52
By :
kanowan
งงอธิบายโค๊ดหน่อยครับ
Date :
2010-04-26 09:38:37
By :
เอนก
ผมก็ใช้แบบนี้ครับ แต่ผมส่งค่าข้าม page ครับ
จะมีส่วนแรกคือ status.php (เป็น page หลัก)
Code (PHP)
<?
session_start();
$_SESSION["pn"]=null;
$_SESSION["s"]=null;
$_SESSION["dorfs"]=null;
$_SESSION["rpo"]=null;
$_SESSION["sitpo"]=null;
$_SESSION["don"]=null;
$_SESSION["fbpo"]=null;
$_SESSION["se"]=null;
$_SESSION["da"]=null;
$_SESSION["dc"]=null;
$_SESSION["it"]=null;
$_SESSION["pd"]=null;
$_SESSION["rq"]=null;
$_SESSION["ctd"]=null;
$_SESSION["dd"]=null;
$_SESSION["os"]=null;
$_SESSION["reg"]=null;
$_SESSION["oc"]=null;
$_SESSION["rag"]=null;
$_SESSION["te"]=null;
if(isset($_POST["search"]))
process();
else
form();
echo "<br/>";
echo "<br/>";
echo "<br/>";
function form(){
echo <<<HTMLBLOCK
<h3>Please choose your wanted status of parts . </h3>
<form method="POST" action="{$_SERVER['PHP_SELF']}">
find from :
<select name="searchtype" id="select" >
<option value="READY" selected>READY</option>
<option value="WAITING">WAITING</option>
<option value="PENDING">PENDING</option>
<option value="REPAIRING">REPAIRING</option>
</select><br>
<input type="submit" name="search" value="search">
</form>
HTMLBLOCK;
}
function exportCSV(){
header('Content-Type: application/x-msexcel');
header('Content-Disposition: inline; filename="export.xls"'); // name filename
header("Pragma: no-cache"); // tell Browser , not need to keep cache
$xlsApp = new COM("Excel.Application") or die("Unable to instanciate excel");
$xlsApp->Visible = 0;
$xlsApp->DisplayAlerts = 0;
//datas written to DB
echo '$reuters_po';
$xlsApp->Quit();
unset($xlsApp);
}
function process(){
$search_term = trim($_POST["search"]);
if(search_term==""){
echo "<font color=\"red\"> failure occurred !! : you did not put the search term";
form();
exit;
}
// $search_term = addslashes($search_term);
$search_field = $_POST["searchtype"];
$cn = mysql_connect("localhost","root","root");
if(!$cn){
echo "Can not connect to server <br>";
exit;
}
mysql_select_db("testdb", $cn);
$sql = "SELECT * FROM sample WHERE status = '$search_field'";
$result = mysql_query($sql,$cn);
echo "<br/>";
echo "<center><h3>Result of following status => $search_field </h3></center>";
echo "<br/>";
echo mysql_error();
$row = mysql_num_rows($result) ;
// echo $row ;
// echo "found quantity : ".mysqli_num_rows($result)."<br><br>\n";
$i = 1;
// echo "check";
?>
<tr> <!-- this will make several tablebut not need to declare table time by time -->
<td> <!-- this will make several tablebut not need to declare table time by time -->
<table width="3000" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" >
<tr bgcolor="#FF6600" class="Hlineitem">
<td width="243"><div align="center"><strong>PO No.</strong></div></td>
<td width="100"><div align="center"><strong>Status</strong></div></td>
<td width="243"><div align="center"><strong>Date Order Received from SRM</strong></div></td>
<td width="100"><div align="center"><strong>Reuters PO</strong></div></td>
<td width="100"><div align="center"><strong>SourceIT PO</strong></div></td>
<td width="100"><div align="center"><strong>Dell Order No</strong></div></td>
<td width="142"><div align="center"><strong>Fujitsu Blanket PO</strong></div></td>
<td width="100"><div align="center"><strong>Supplier Entity </strong></div></td>
<td width="300"><div align="center"><strong>Delivery Address </strong></div></td>
<td width="100"><div align="center"><strong>Delivery Contact </strong></div></td>
<td width="150"><div align="center"><strong>Item</strong></div></td>
<td width="350"><div align="center"><strong>Part Description </strong></div></td>
<td width="100"><div align="center"><strong>Request Qty </strong></div></td>
<td width="200"><div align="center"><strong>Country Target Date </strong></div></td>
<td width="100"><div align="center"><strong>Delivery Date </strong></div></td>
<td width="100"><div align="center"><strong>Order Status </strong></div></td>
<td width="100"><div align="center"><strong>Region</strong></div></td>
<td width="400"><div align="center"><strong>Order Comments </strong></div></td>
<td width="50"><div align="center"><strong>RAG</strong></div></td>
<td width="350"><div align="center"><strong>Type Explanation </strong></div></td>
</tr>
<!--</table>-->
<?
$sql = "SELECT * FROM sample where status = '$search_field'";
$result = mysql_query($sql,$cn);
$count = 0 ;
while($r=mysql_fetch_assoc($result)){
$LineItems[] =$r;
}
mysql_free_result($result);
if (count($LineItems)>0){
foreach($LineItems as $rowData)
{
?>
<!--<table width="3000" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" > -->
<tr>
<td width="100"><div align="center"><?=$rowData['pono']?></div></td> <? $_SESSION["pn"][]=$rowData['pono'] ?>
<td width="100"><div align="center"><?=$rowData['status']?></div></td> <? $_SESSION["s"][]=$rowData['status'] ?>
<td width="243"><div align="center"><?=$rowData['date_order_received_from_srm']?></div></td>
<? $_SESSION["dorfs"][]=$rowData['date_order_received_from_srm'] ?>
<td width="100"><div align="center"><?=$rowData['reuters_po']?></div></td> <? $_SESSION["rpo"][]=$rowData['reuters_po'] ?>
<td width="100"><div align="center"><?=$rowData['sourceit_po']?></div></td> <? $_SESSION["sitpo"][]=$rowData['sourceit_po'] ?>
<td width="100"><div align="center"><?=$rowData['dell_order_no']?></div></td> <? $_SESSION["don"][]=$rowData['dell_order_no'] ?>
<td width="142"><div align="center"><?=$rowData['fujitsu_blanket_po']?></div></td> <? $_SESSION["fbpo"][]=$rowData['fujitsu_blanket_po'] ?>
<td width="100"><div align="center"><?=$rowData['supplier_entity']?></div></td> <? $_SESSION["se"][]=$rowData['supplier_entity'] ?>
<td width="300"><div align="center"><?=$rowData['delivery_address']?></div></td> <? $_SESSION["da"][]=$rowData['delivery_address'] ?>
<td width="100"><div align="center"><?=$rowData['delivery_contact']?></div></td> <? $_SESSION["dc"][]=$rowData['delivery_contact'] ?>
<td width="150"><div align="center"><?=$rowData['item']?></div></td> <? $_SESSION["it"]=$rowData['item'] ?>
<td width="350"><div align="center"><?=$rowData['part_description']?></div></td> <? $_SESSION["pd"][]=$rowData['part_description'] ?>
<td width="100"><div align="center"><?=$rowData['request_qty']?></div></td> <? $_SESSION["rq"][]=$rowData['request_qty'] ?>
<td width="200"><div align="center"><?=$rowData['country_target_date']?></div></td> <? $_SESSION["ctd"][]=$rowData['country_target_date'] ?>
<td width="100"><div align="center"><?=$rowData['delivery_date']?></div></td> <? $_SESSION["dd"][]=$rowData['deliver_date'] ?>
<td width="100"><div align="center"><?=$rowData['order_status']?></div></td> <? $_SESSION["os"][]=$rowData['order_status'] ?>
<td width="100"><div align="center"><?=$rowData['region']?></div></td> <? $_SESSION["reg"][]=$rowData['region'] ?>
<td width="400"><div align="center"><?=$rowData['order_comments']?></div></td> <? $_SESSION["oc"][]=$rowData['order_comments'] ?>
<td width="50"><div align="center"><?=$rowData['rag']?></div></td> <? $_SESSION["rag"][]=$rowData['rag'] ?>
<td width="350"><div align="center"><?=$rowData['type_explanation']?></div></td> <? $_SESSION["te"][]=$rowData['type_explanation']?>
</tr>
<!-- </table>-->
<?
} ?>
<?
} ?>
</table>
</td> <!-- this will make several tablebut not need to declare table time by time -->
</tr> <!-- this will make several tablebut not need to declare table time by time -->
<br /> <br />
<form id="form1" name="form1" method="post" action="">
<center><label>
<p><a href="status.php"><img src="ip_icon_02_Back.png" width="40" height="40" border="0" /></a> <a href="report.php"><img src="report_icon.png" width="40" height="40" border="0" /></a> </p>
</label></center>
</form>
<?
}
?>
และส่วนที่สองคือ report.php เป็นส่วนต่อจาก status.php โดยการคลิกที่ ปุ่ม image button (ปุ่ม report) แล้วจะลิงค์มาส่วนนี้
Code (PHP)
<?
header('Content-Type: application/x-msexcel');
header('Content-Disposition: inline; filename="export.xls"'); // name filename
header("Pragma: no-cache"); // tell Browser , not need to keep cache
$xlsApp = new COM("Excel.Application") or die("Unable to instanciate excel");
$xlsApp->Visible = 0;
$xlsApp->DisplayAlerts = 0;
//datas written to DB
for($i=0;$i<count($_SESSION["pn"]);$i++)
{
echo "check".$i ;
echo $_SESSION["pn"][$i]."<br>";
}
echo $_SESSION["dorfs"];
$xlsApp->Quit();
unset($xlsApp);
?>
แต่พอมาตอน report.php จะปรินท์ค่ามันออกมาดู มันไม่เห็นมีค่าที่เก็บไว้เลยครับ T T
Date :
2010-10-15 13:17:17
By :
gogkub
Load balance : Server 04