ขึ้น error ว่า Warning: Invalid argument supplied for foreach() in ช่วยดูทีค่ะ
จุดที่ผิด มันคงอยู่ก่อนบรรทัดที่ 145 ครับ
เพราะตัวแปรที่คุณเอาไปใช้กับ foreach มันไม่ใช่ array หรือ object
Date :
2013-06-11 21:01:39
By :
cookiephp
ช่วยดูโค้ดทีค่ะ
Code (PHP)
<form method="post" action="receive_material2_add.php">
<table width="100%" height="779" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td align="left" valign="top" bordercolor="#CCCCCC"><br />
<table width="228" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><span class="style12">ตรวจรับวัตถุดิบ</span></td>
</tr>
</table>
<br />
<table width="493" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><p><span class="style14 style14">ร้านวรรณของฝาก<br />
99/1 หมู่ 4 ถ.สุวรรณศร ต.ประจันตคาม อ.ประจันตคาม จ.ปราจีนบุรี 25130 <br />
โทร</span><span class="style14"> : 037291175 มือถือ : 0867909385 อีเมล์ :</span> <span class="style14">[email protected] </span><br />
</p> </td>
</tr>
</table>
<br />
<table width="243" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="102" align="right"><span class="style14">เลขที่ใบสั่งซื้อ : </span></td>
<td width="159"> <?=$sess_ord[0]?></td>
</tr>
<tr>
<td align="right"><span class="style14">
วันที่ตรวจรับ :
</span></td>
<td> <span class="style15">
<?=datethai($sess_ord[1])?>
</span></td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="265" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right"><span class="style14">ชื่อตัวแทนจำหน่าย :</span></td>
<td width="120"><span class="style14"> <?=$sess_ord[3]?></span></td>
</tr>
</table>
<table width="708" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right" valign="top"><span class="style14">ที่อยู่ : </span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[4]?> จ.<span class="style3"><?=$sess_ord[5]?>
<?=$sess_ord[6]?></span></span></td>
</tr>
<tr>
<td align="right"><span class="style14">โทร :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[7]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">มือถือ :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[8]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">อีเมล์ :</span></td>
<td width="563" valign="bottom"> <?=$sess_ord[9]?> </td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="896" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#666666">
<tr>
<td width="43" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ลำดับ</span></td>
<td width="76" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">รหัสวัตถุดิบ</span></td>
<td width="186" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ชื่อวัตถุดิบ</span></td>
<td width="75" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนสั่งซื้อ</span></td>
<td width="77" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนที่รับ</span></td>
<td width="123" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาต้นทุนต่อหน่วย</span></td>
<td width="104" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาขายต่อหน่วย</span></td>
<td width="72" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาสุทธิ</span></td>
</tr>
<?
$i=0;
foreach($sess_detail as $value){ // บรรทัดที่แจ้งว่า error //
?>
<tr>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[0]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[1]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[2]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[3]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input type="text" align="middle" name="qty[]" value="<? echo $value[3]?>" maxlength="3" size="3"/></span></td>
<?
$sqll="select * from material where m_id='$value[1]'";
$quee=mysql_query($sqll);
$fett=mysql_fetch_array($quee);
?>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<? $id=$value[1];?>
<input name="ordermatprice[]" type="text" id="ordermatprice[]" value="<? if($_SESSION['ses_matprice'][$i]=='')
{echo $fett['m_cost'];} else{echo $_SESSION['ses_matprice'][$i];}?>"placeholder="<?=number_format($fett['m_cost'],2);?>" size= "10"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input name="pri[<? echo $value[1]?>]" type="text" id="pri[]" value="<? if($_SESSION['pri'][$value[1]]!="")
{echo $_SESSION['pri'][$value[1]];}else{echo number_format($fett['m_price'],2);}?>" size="10" placeholder="<?=number_format($fett['m_price'],2);?>"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo number_format($value[6],2);?>
</span></td>
</tr>
<? $total=$value[6]+$total; $i++;}?>
<tr>
<td colspan="6" align="center" bordercolor="#999999" bgcolor="#FFFFCC"> </td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">ราคารวมสุทธิ</span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><?=number_format($total,2);?></span></td>
</tr>
</table>
<br />
<br />
<table width="221" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><input type="submit" name="Submit" value="คำนวณ"/>
<input type="submit" name="Submit2" value="ตรวจรับวัตถุดิบ"/>
<input type="submit" name="Submit22" value="ยกเลิก"/>
</td>
</tr>
</table>
<br />
<br />
</td>
</tr>
</table>
</form>
Date :
2013-06-11 21:29:27
By :
jungnaka
$sess_detail มันมาจากไหนครับ ต้องหาที่มาของตัวแปรนี้
ดูจากชื่อ น่าจะเป็นตัวแปร session ที่สร้างด้วย session_register() ลองหาดูํครับ
แล้วค่อยๆ ไล่มา ว่ามันมีการกำหนดค่าที่ใด
ป.ล. ทำไมช่วงนี้คนนิยมเอาโค้ดเก่าสมัยพระเจ้าเหามาดัดแปลงกันจัง
Date :
2013-06-11 21:38:25
By :
cookiephp
session มีปัญหาอีกแล้วมั้ง $sess_detail
Date :
2013-06-11 21:40:32
By :
randOmizE
หรือถ้าอยากแก้แบบง่ายๆ เลย ก็เพิ่มตรงนี้ก่อน foreach และแก้นิดนึงตรง foreach ครับ
Code (PHP)
if (!isset($sess_detail) || !is_array($sess_detail)) {
$sess_detail_copy = array();
} else {
$sess_detail_copy = $sess_detail;
}
foreach($sess_detail_copy as $value){
Date :
2013-06-11 21:41:48
By :
cookiephp
ลองแก้ดูหาย error แต่ค่ายังไม่ขึ้นค่ะ
Code (PHP)
<?
if (!isset($sess_detail) || !is_array($sess_detail)) {
$sess_detail_copy = array();
} else {
$sess_detail_copy = $sess_detail;
}
$i=0;
foreach($sess_detail_copy as $value){
?>
Date :
2013-06-11 21:58:46
By :
jungnaka
ใช่ครับ ผมทำแค่ให้ error มันหาย
ถ้าอยากให้ค่ามันขึ้น คุณต้องหาครับ ว่ามันมีที่มาจากไหน ไอ้ตัวแปรนี้เนี่ย
Date :
2013-06-11 22:02:19
By :
cookiephp
จากตรงนี้ค่ะ
Code (PHP)
$select_detail="select * from ordermat_detail , material where material.m_id = ordermat_detail.m_id and ormat_id = '$ormat_id' order by ormatdetail_id";
$result_detail=mysql_query($select_detail);
while($read_detail=mysql_fetch_array($result_detail)){
$_SESSION['sess_detail'][]=array($read_detail['ormatdetail_id'],$read_detail['m_id'],$read_detail['m_name'],$read_detail['ormat_qty'],
$read_detail['ormat_qtyrec'],$read_detail['ormat_price'],$read_detail['ormat_totalprice']);
Date :
2013-06-11 22:16:05
By :
jungnaka
มันอยู่ไฟล์เดียวกันกับโค๊ดข้างบนหรอครับ หรือว่า คนละไฟล์ ถ้าคนละไฟล์ก็เอามาทั้งหมด ตัดมาแบบนี้ดูไม่รู้หรอกครับว่าหายไปตรงไหน
Date :
2013-06-11 22:38:04
By :
randOmizE
receivematerial.php
Code (PHP)
<td width="65" align="center" class="style3 style18"><a href="receive_material_add.php?ormatid=<?=$read['ormat_id']?>" class="style18">รับวัตถุดิบ</a></td>
receive_material_add.php
<?
$ormat_id=$_REQUEST['ormat_id'];
$select_ord="select * from ordermat , supplier where supplier.sup_id=ordermat.sup_id and ormat_id='$ormat_id'";
$result_ord=mysql_query($select_ord);
$read_ord=mysql_fetch_array($result_ord);
$_SESSION['sess_ord']=array($read_ord['ormat_id'],date("Y-m-d"),$read_ord['sup_id'], $read_ord['sup_name'],$read_ord['sup_addr'], $read_ord['sup_province'],$read_ord['sup_zipcode'],$read_ord['sup_tel'], $read_ord['sup_mobile'],$read_ord['sup_email']);
$select_detail="select * from ordermat_detail , material where material.m_id = ordermat_detail.m_id and ormat_id = '$ormat_id' order by ormatdetail_id";
$result_detail=mysql_query($select_detail);
while($read_detail=mysql_fetch_array($result_detail)){
$_SESSION['sess_detail'][]=array($read_detail['ormatdetail_id'],$read_detail['m_id'],$read_detail['m_name'],$read_detail['ormat_qty'],
$read_detail['ormat_qtyrec'],$read_detail['ormat_price'],$read_detail['ormat_totalprice']);
}
echo "<script>window.location='receive_material2.php'</script>";
?>
receive_material2.php
<table width="243" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="102" align="right"><span class="style14">เลขที่ใบสั่งซื้อ : </span></td>
<td width="159"> <?=$sess_ord[0]?></td>
</tr>
<tr>
<td align="right"><span class="style14">
วันที่ตรวจรับ :
</span></td>
<td> <span class="style15">
<?=datethai($sess_ord[1])?>
</span></td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="265" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right"><span class="style14">ชื่อตัวแทนจำหน่าย :</span></td>
<td width="120"><span class="style14"> <?=$sess_ord[3]?></span></td>
</tr>
</table>
<table width="708" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right" valign="top"><span class="style14">ที่อยู่ : </span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[4]?> จ.<span class="style3"><?=$sess_ord[5]?>
<?=$sess_ord[6]?></span></span></td>
</tr>
<tr>
<td align="right"><span class="style14">โทร :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[7]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">มือถือ :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[8]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">อีเมล์ :</span></td>
<td width="563" valign="bottom"> <?=$sess_ord[9]?> </td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="896" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#666666">
<tr>
<td width="43" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ลำดับ</span></td>
<td width="76" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">รหัสวัตถุดิบ</span></td>
<td width="186" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ชื่อวัตถุดิบ</span></td>
<td width="75" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนสั่งซื้อ</span></td>
<td width="77" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนที่รับ</span></td>
<td width="123" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาต้นทุนต่อหน่วย</span></td>
<td width="104" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาขายต่อหน่วย</span></td>
<td width="72" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาสุทธิ</span></td>
</tr>
<? if (!isset($sess_detail) || !is_array($sess_detail)) {
$sess_detail_copy = array();
} else {
$sess_detail_copy = $sess_detail;
}
$i=0;
foreach($sess_detail_copy as $value){
?>
<tr>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[0]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[1]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[2]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[3]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input type="text" align="middle" name="qty[]" value="<? echo $value[3]?>" maxlength="3" size="3"/></span></td>
<?
$sqll="select * from material where m_id='$value[1]'";
$quee=mysql_query($sqll);
$fett=mysql_fetch_array($quee);
?>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<? $id=$value[1];?>
<input name="ordermatprice[]" type="text" id="ordermatprice[]" value="<? if($_SESSION['ses_matprice'][$i]=='')
{echo $fett['m_cost'];} else{echo $_SESSION['ses_matprice'][$i];}?>"placeholder="<?=number_format($fett['m_cost'],2);?>" size= "10"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input name="pri[<? echo $value[1]?>]" type="text" id="pri[]" value="<? if($_SESSION['pri'][$value[1]]!="")
{echo $_SESSION['pri'][$value[1]];}else{echo number_format($fett['m_price'],2);}?>" size="10" placeholder="<?=number_format($fett['m_price'],2);?>"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo number_format($value[6],2);?>
</span></td>
</tr>
<? $total=$value[6]+$total; $i++;}?>
<tr>
<td colspan="6" align="center" bordercolor="#999999" bgcolor="#FFFFCC"> </td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">ราคารวมสุทธิ</span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><?=number_format($total,2);?></span></td>
</tr>
</table>
Date :
2013-06-11 22:50:44
By :
jungnaka
เปลี่ยนตัวแปร $sess_detail ในทุกจุดที่มี
ให้เป็น $_SESSION['sess_detail'] ให้หมดครับ
เช่นแบบนี้
<? if (!isset($_SESSION['sess_detail']) || !is_array($_SESSION['sess_detail'])) {
$sess_detail_copy = array();
} else {
$sess_detail_copy = $_SESSION['sess_detail'];
}
$i=0;
foreach($sess_detail_copy as $value){
?>
Date :
2013-06-11 22:58:29
By :
cookiephp
ไม่ได้ session_start() ไว้ที่หัวมั้งครับ
ลองดูแบบนี้
Code (PHP)
<?php
session_start();
$ormat_id=$_REQUEST['ormat_id'];
$select_ord="select * from ordermat , supplier where supplier.sup_id=ordermat.sup_id and ormat_id='$ormat_id'";
$result_ord=mysql_query($select_ord);
$read_ord=mysql_fetch_array($result_ord);
$_SESSION['sess_ord']=array($read_ord['ormat_id'],date("Y-m-d"),$read_ord['sup_id'], $read_ord['sup_name'],$read_ord['sup_addr'],$read_ord['sup_province'], $read_ord['sup_zipcode'],$read_ord['sup_tel'],$read_ord['sup_mobile'],$read_ord['sup_email']);
$select_detail="select * from ordermat_detail , material where material.m_id = ordermat_detail.m_id and ormat_id = '$ormat_id' order by ormatdetail_id";
$result_detail=mysql_query($select_detail);
while($read_detail=mysql_fetch_array($result_detail)){ // ต้องใช้ while เลยหรอครับ
$_SESSION['sess_detail'] = array($read_detail['ormatdetail_id'],$read_detail['m_id'],$read_detail['m_name'],$read_detail['ormat_qty'],
$read_detail['ormat_qtyrec'],$read_detail['ormat_price'],$read_detail['ormat_totalprice']);
}
echo "<script>window.location='receive_material2.php'</script>";
receive_material2.php
Code (PHP)
<?php
session_start();
$sess_detail = $_SESSION['sess_detail'];
<table width="243" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="102" align="right"><span class="style14">เลขที่ใบสั่งซื้อ : </span></td>
<td width="159"> <?=$sess_ord[0]?></td>
</tr>
<tr>
<td align="right"><span class="style14">
วันที่ตรวจรับ :
</span></td>
<td> <span class="style15">
<?=datethai($sess_ord[1])?>
</span></td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="265" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right"><span class="style14">ชื่อตัวแทนจำหน่าย :</span></td>
<td width="120"><span class="style14"> <?=$sess_ord[3]?></span></td>
</tr>
</table>
<table width="708" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right" valign="top"><span class="style14">ที่อยู่ : </span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[4]?> จ.<span class="style3"><?=$sess_ord[5]?>
<?=$sess_ord[6]?></span></span></td>
</tr>
<tr>
<td align="right"><span class="style14">โทร :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[7]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">มือถือ :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[8]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">อีเมล์ :</span></td>
<td width="563" valign="bottom"> <?=$sess_ord[9]?> </td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="896" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#666666">
<tr>
<td width="43" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ลำดับ</span></td>
<td width="76" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">รหัสวัตถุดิบ</span></td>
<td width="186" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ชื่อวัตถุดิบ</span></td>
<td width="75" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนสั่งซื้อ</span></td>
<td width="77" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนที่รับ</span></td>
<td width="123" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาต้นทุนต่อหน่วย</span></td>
<td width="104" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาขายต่อหน่วย</span></td>
<td width="72" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาสุทธิ</span></td>
</tr>
$i=0;
foreach($sess_detail as $value){
?>
<tr>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[0]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[1]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[2]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[3]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input type="text" align="middle" name="qty[]" value="<? echo $value[3]?>" maxlength="3" size="3"/></span></td>
<?
$sqll="select * from material where m_id='$value[1]'";
$quee=mysql_query($sqll);
$fett=mysql_fetch_array($quee);
?>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<? $id=$value[1];?>
<input name="ordermatprice[]" type="text" id="ordermatprice[]" value="<? if($_SESSION['ses_matprice'][$i]=='')
{echo $fett['m_cost'];} else{echo $_SESSION['ses_matprice'][$i];}?>"placeholder="<?=number_format($fett['m_cost'],2);?>" size= "10"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input name="pri[<? echo $value[1]?>]" type="text" id="pri[]" value="<? if($_SESSION['pri'][$value[1]]!="")
{echo $_SESSION['pri'][$value[1]];}else{echo number_format($fett['m_price'],2);}?>" size="10" placeholder="<?=number_format($fett['m_price'],2);?>"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo number_format($value[6],2);?>
</span></td>
</tr>
<? $total=$value[6]+$total; $i++;}?>
<tr>
<td colspan="6" align="center" bordercolor="#999999" bgcolor="#FFFFCC"> </td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">ราคารวมสุทธิ</span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><?=number_format($total,2);?></span></td>
</tr>
</table>
Date :
2013-06-11 23:07:45
By :
randOmizE
ค่ายังไม่มาเลยค่ะ แหะๆ
Date :
2013-06-11 23:15:37
By :
jungnaka
ใส่ session_start(); ทั้งสองหน้ารึยังครับ
ถ้า ordermat_detail , material มีข้อมูลยังไงก็ต้องแสดงครับ
Date :
2013-06-11 23:46:38
By :
{Cyberman}
ใส่ session start(); ทั้งสอง แล้วค่ะ ทำตามแล้ว ทำไมค่าไม่มาอะคะ
Date :
2013-06-12 12:59:35
By :
jungnaka
เอาที่แก้แล้วมาดูใหม่ครับ ทั้ง 2 หน้าเลย
Date :
2013-06-12 13:03:43
By :
randOmizE
receive_material_add.php
<?php
session_start();
include "connect.php";
mysql_query("SET NAMES'utf-8'");
$ormat_id=$_REQUEST['ormat_id'];
$select_ord="select * from ordermat , supplier where supplier.sup_id=ordermat.sup_id and ormat_id='$ormat_id'";
$result_ord=mysql_query($select_ord);
$read_ord=mysql_fetch_array($result_ord);
$_SESSION['sess_ord']=array($read_ord['ormat_id'],date("Y-m-d"),$read_ord['sup_id'],$read_ord['sup_name'],$read_ord['sup_addr'],$read_ord['sup_province'],$read_ord['sup_zipcode'],$read_ord['sup_tel'],$read_ord['sup_mobile'],$read_ord['sup_email']);
$select_detail="select * from ordermat_detail , material where material.m_id = ordermat_detail.m_id and ormat_id = '$ormat_id' order by ormatdetail_id";
$result_detail=mysql_query($select_detail);
while($read_detail=mysql_fetch_array($result_detail)){
$_SESSION['sess_detail'][]=array($read_detail['ormatdetail_id'],$read_detail['m_id'],$read_detail['m_name'],$read_detail['ormat_qty'],
$read_detail['ormat_qtyrec'],$read_detail['ormat_price'],$read_detail['ormat_totalprice']);
}
echo "<script>window.location='receive_material2.php'</script>";
?>
receive_material2.php
<?php
session_start();
include "connect.php";
include "function.php";
mysql_query("SET NAMES'utf-8'");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$sess_detail = $_SESSION['sess_detail'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ตรวจรับวัตถุดิบ</title>
<form method="post" action="receive_material2_add.php">
<table width="100%" height="779" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr>
<td align="left" valign="top" bordercolor="#CCCCCC"><br />
<table width="228" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><span class="style12">ตรวจรับวัตถุดิบ</span></td>
</tr>
</table>
<br />
<table width="243" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td width="102" align="right"><span class="style14">เลขที่ใบสั่งซื้อ : </span></td>
<td width="159"> <?=$sess_ord[0]?></td>
</tr>
<tr>
<td align="right"><span class="style14">
วันที่ตรวจรับ :
</span></td>
<td> <span class="style15">
<?=datethai($sess_ord[1])?>
</span></td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="265" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right"><span class="style14">ชื่อตัวแทนจำหน่าย :</span></td>
<td width="120"><span class="style14"> <?=$sess_ord[3]?></span></td>
</tr>
</table>
<table width="708" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="145" align="right" valign="top"><span class="style14">ที่อยู่ : </span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[4]?> จ.<span class="style3"><?=$sess_ord[5]?>
<?=$sess_ord[6]?></span></span></td>
</tr>
<tr>
<td align="right"><span class="style14">โทร :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[7]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">มือถือ :</span></td>
<td width="563" valign="bottom"><span class="style14"> <?=$sess_ord[8]?></span></td>
</tr>
<tr>
<td align="right"><span class="style14">อีเมล์ :</span></td>
<td width="563" valign="bottom"> <?=$sess_ord[9]?> </td>
</tr>
</table>
<p><br />
<br />
</p>
<table width="896" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#666666">
<tr>
<td width="43" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ลำดับ</span></td>
<td width="76" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">รหัสวัตถุดิบ</span></td>
<td width="186" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ชื่อวัตถุดิบ</span></td>
<td width="75" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนสั่งซื้อ</span></td>
<td width="77" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">จำนวนที่รับ</span></td>
<td width="123" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาต้นทุนต่อหน่วย</span></td>
<td width="104" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาขายต่อหน่วย</span></td>
<td width="72" align="center" bordercolor="#999999" bgcolor="#DFEFFF"><span class="style14">ราคาสุทธิ</span></td>
</tr>
<? if (!isset($_SESSION['sess_detail']) || !is_array($_SESSION['sess_detail'])) {
$sess_detail_copy = array();
} else {
$sess_detail_copy = $_SESSION['sess_detail'];
}
$i=0;
foreach($sess_detail_copy as $value){
?>
<tr>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[0]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[1]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[2]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo $value[3]?></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input type="text" align="middle" name="qty[]" value="<? echo $value[3]?>" maxlength="3" size="3"/></span></td>
<?
$sqll="select * from material where m_id='$value[1]'";
$quee=mysql_query($sqll);
$fett=mysql_fetch_array($quee);
?>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<? $id=$value[1];?>
<input name="ordermatprice[]" type="text" id="ordermatprice[]" value="<? if($_SESSION['ses_matprice'][$i]=='')
{echo $fett['m_cost'];} else{echo $_SESSION['ses_matprice'][$i];}?>"placeholder="<?=number_format($fett['m_cost'],2);?>" size= "10"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">
<input name="pri[<? echo $value[1]?>]" type="text" id="pri[]" value="<? if($_SESSION['pri'][$value[1]]!="")
{echo $_SESSION['pri'][$value[1]];}else{echo number_format($fett['m_price'],2);}?>" size="10" placeholder="<?=number_format($fett['m_price'],2);?>"/></span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><? echo number_format($value[6],2);?>
</span></td>
</tr>
<? $total=$value[6]+$total; $i++;}?>
<tr>
<td colspan="6" align="center" bordercolor="#999999" bgcolor="#FFFFCC"> </td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14">ราคารวมสุทธิ</span></td>
<td align="center" bordercolor="#999999" bgcolor="#FFFFCC"><span class="style14"><?=number_format($total,2);?></span></td>
</tr>
</table>
</tr>
</table>
</form>
Date :
2013-06-12 13:08:17
By :
jungnaka
receive_material_add.php
เอาโค๊ดนี้ไปรันดูว่าเกิดไรขึ้น
Code (PHP)
<?php
session_start();
include "connect.php";
mysql_query("SET NAMES'utf-8'");
$ormat_id=$_REQUEST['ormat_id'];
$select_ord="select * from ordermat , supplier where supplier.sup_id=ordermat.sup_id and ormat_id='$ormat_id'";
$result_ord=mysql_query($select_ord);
$read_ord=mysql_fetch_array($result_ord);
$_SESSION['sess_ord']=array($read_ord['ormat_id'],date("Y-m-d"),$read_ord['sup_id'],$read_ord['sup_name'],$read_ord['sup_addr'],$read_ord['sup_province'],$read_ord['sup_zipcode'],$read_ord['sup_tel'],$read_ord['sup_mobile'],$read_ord['sup_email']);
$select_detail="select * from ordermat_detail , material where material.m_id = ordermat_detail.m_id and ormat_id = '$ormat_id' order by ormatdetail_id";
$result_detail=mysql_query($select_detail);
while($read_detail=mysql_fetch_array($result_detail)){
$_SESSION['sess_detail'][]=array($read_detail['ormatdetail_id'],$read_detail['m_id'],$read_detail['m_name'],$read_detail['ormat_qty'],
$read_detail['ormat_qtyrec'],$read_detail['ormat_price'],$read_detail['ormat_totalprice']);
}
//echo "<script>window.location='receive_material2.php'</script>";
print_r($_SESSION['sess_detail']); // ดูว่าใส่ค่าได้ป่าว
?>
Date :
2013-06-12 13:14:22
By :
randOmizE
ขึ้นหน้าว่างป่าวค่ะ
URL เป็นแบบนี้ receive_material_add.php?ormatid=OR0001
Date :
2013-06-12 14:23:45
By :
jungnaka
ปัญหาคงอยู่ที่การดึงข้อมูลออกมาไม่ได้มั้งครับ
Code (PHP)
<?php
session_start();
include "connect.php";
mysql_query("SET NAMES'utf-8'");
$ormat_id=$_REQUEST['ormat_id'];
$select_ord="select * from ordermat , supplier where supplier.sup_id=ordermat.sup_id and ormat_id='$ormat_id'";
$result_ord=mysql_query($select_ord); // จุดนี้
$read_ord=mysql_fetch_array($result_ord);
$_SESSION['sess_ord']=array($read_ord['ormat_id'],date("Y-m-d"),$read_ord['sup_id'],$read_ord['sup_name'],$read_ord['sup_addr'],$read_ord['sup_province'],$read_ord['sup_zipcode'],$read_ord['sup_tel'],$read_ord['sup_mobile'],$read_ord['sup_email']);
$select_detail="select * from ordermat_detail , material where material.m_id = ordermat_detail.m_id and ormat_id = '$ormat_id' order by ormatdetail_id"; // และจุดนี้
$result_detail=mysql_query($select_detail);
while($read_detail=mysql_fetch_array($result_detail)){
$_SESSION['sess_detail'][]=array($read_detail['ormatdetail_id'],$read_detail['m_id'],$read_detail['m_name'],$read_detail['ormat_qty'],
$read_detail['ormat_qtyrec'],$read_detail['ormat_price'],$read_detail['ormat_totalprice']);
}
//echo "<script>window.location='receive_material2.php'</script>";
print_r($_SESSION['sess_detail']); // ดูว่าใส่ค่าได้ป่าว
?>
Date :
2013-06-12 14:45:13
By :
randOmizE
ได้แล้วค่ะ ค่าที่ส่งมากับลิ้งก่อนหน้า receive_material_add ผิด ขอบคุณมากๆค่ะ
Date :
2013-06-12 14:59:02
By :
jungnaka
Load balance : Server 02