|
 |
|
สอบถามปัญหาผม query ข้อมูลมาแต่พอ while แล้วข้อมูลมันลงไม่ตรงกับตารางที่กำหนดอ่ะครับ ช่วยดูให้ที |
|
 |
|
|
 |
 |
|
Code (PHP)
<link href="../style.css" rel="stylesheet" type="text/css">
<?php
session_start();
$sql = "SELECT sp_stock_import.part_id , sp_stock_import.part_name , sp_type.id_type , SUM(amount) AS Amount ";
$sql .= "FROM sp_stock_import ";
$sql .= "INNER JOIN sp_stock_list ON sp_stock_list.part_id = sp_stock_import.part_id ";
$sql .= "INNER JOIN sp_type ON sp_type.id_type = sp_stock_list.id_type ";
$sql .= "GROUP BY sp_stock_list.part_id, sp_stock_import.part_name, sp_type.id_type";
$result = mysql_db_query($dbname,$sql);
if($_SESSION["username"]=='')
{
?>
<form id="center" name="form1" method="post" action="warehouse/db_connect.php">
<table width="200" border="0" align="center" style="margin-top:60px;">
<tr>
<td colspan="2" align="center" height="40">Staff Login</td>
</tr>
<tr>
<td>User ID</td>
<td><input type="text" name="tb_username" id="textfield" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="tb_password" id="textfield2" /></td>
</tr>
<tr>
<td colspan="2" align="center" height="30"><input type="submit" name="bt_submit" id="bt_submit" value="Submit" /></td>
<input type="hidden" name="swap" id="swap" value="1" />
</tr>
</table>
</form>
<?
}
else
{
?>
<div class="date" style="margin-top:-12px;"><?=$_SESSION["username"]?> <img src="images/27-May-13 9-38-30 AM.png" height="25" width="25" /><a href="warehouse/test3.php">Warehouse</a> <img src="images/Apps-session-logout-icon.png" height="25" width="25" /><a href="warehouse/logout.php">Logout</a></div>
<table align="center" width="80%" height="130px" border="0" style="margin-top:10px;">
<?
$sql = "SELECT * FROM sp_type";
$qr = mysql_query($sql);
while($rs2 = mysql_fetch_array($qr))
{
?>
<tr>
<td colspan="2" align="center" style="font-family:'Times New Roman', Times, serif; font-size:16px; color:blue; border-bottom:1px solid #bbbbbb; padding-bottom:2px;"><?=$rs2[name_type];?></td>
<tr>
<?
if($_SESSION["lang"]!="th")
{
echo'
<td align="left" style="color:black;">Product Name</td>
<td align="left" style="color:black;">Amount</td>
';
}
else
{
echo'
<td align="left" style="color:black;">ชื่อสินค้า</td>
<td align="left" style="color:black;">จำนวน</td>
';
}
?>
</tr>
<?
while($rs=mysql_fetch_assoc($result))
{
$variable1 = $rs["part_id"];
$variable2 = $rs["part_name"];
$variable3 = $rs["Amount"];
if($rs[id_type]==$rs2[id_type])
{
?>
<tr>
<td align="left" style="border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic"><? echo $variable2; ?></td>
<td align="left" style="border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic"><? echo $variable3; ?></td>
</tr>
<?
}
else
{
?>
<tr>
<td colspan="2" align="center" style="border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic">No Product Available</td>
</tr>
<?
}
}
?>
</tr>
<?
}
mysql_free_result($result);
?>
</table>
<? } ?>
มันจะเป็นแบบนี้ครับ

จริงๆตรง no product available มันต้องไปอยู่ตรงพวก robot, accessories อ่ะครับ ช่วยดูทีครับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2013-05-28 10:10:56 |
By :
golden014 |
View :
849 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<link href="../style.css" rel="stylesheet" type="text/css">
<?php
session_start();
$sql = "SELECT sp_stock_import.part_id , sp_stock_import.part_name , sp_type.id_type , SUM(amount) AS Amount ";
$sql .= "FROM sp_stock_import ";
$sql .= "INNER JOIN sp_stock_list ON sp_stock_list.part_id = sp_stock_import.part_id ";
$sql .= "INNER JOIN sp_type ON sp_type.id_type = sp_stock_list.id_type ";
$sql .= "GROUP BY sp_stock_list.part_id, sp_stock_import.part_name, sp_type.id_type";
$result = mysql_db_query($dbname,$sql);
if($_SESSION["username"]==''){
?>
<form id="center" name="form1" method="post" action="warehouse/db_connect.php">
<table width="200" border="0" align="center" style="margin-top:60px;">
<tr>
<td colspan="2" align="center" height="40">Staff Login</td>
</tr>
<tr>
<td>User ID</td>
<td><input type="text" name="tb_username" id="textfield" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="tb_password" id="textfield2" /></td>
</tr>
<tr>
<td colspan="2" align="center" height="30"><input type="submit" name="bt_submit" id="bt_submit" value="Submit" /></td>
<input type="hidden" name="swap" id="swap" value="1" />
</tr>
</table>
</form>
<?
}
else{
?>
<div class="date" style="margin-top:-12px;"><?=$_SESSION["username"]?> <img src="images/27-May-13 9-38-30 AM.png" height="25" width="25" /><a href="warehouse/test3.php">Warehouse</a> <img src="images/Apps-session-logout-icon.png" height="25" width="25" /><a href="warehouse/logout.php">Logout</a></div>
<table align="center" width="80%" height="130px" border="0" style="margin-top:10px;">
<?
$sql = "SELECT * FROM sp_type";
$qr = mysql_query($sql);
while($rs2 = mysql_fetch_array($qr)){
?>
<tr>
<td colspan="2" align="center" style="font-family:'Times New Roman', Times, serif; font-size:16px; color:blue; border-bottom:1px solid #bbbbbb; padding-bottom:2px;"><?=$rs2["name_type"];?></td>
</tr>
<?
if($_SESSION["lang"]!="th"){
echo '<tr>';
echo '<td align="left" style="color:black;">Product Name</td>';
echo '<td align="left" style="color:black;">Amount</td>';
echo '</tr>';
}
else{
echo '<tr>';
echo '<td align="left" style="color:black;">ชื่อสินค้า</td>';
echo '<td align="left" style="color:black;">จำนวน</td>';
echo '</tr>';
}
while($rs=mysql_fetch_assoc($result)){
$variable1 = $rs["part_id"];
$variable2 = $rs["part_name"];
$variable3 = $rs["Amount"];
if($rs["id_type"]==$rs2["id_type"]){
?>
<tr>
<td align="left" style="border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic"><? echo $variable2; ?></td>
<td align="left" style="border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic"><? echo $variable3; ?></td>
</tr>
<?
}
else{
?>
<tr>
<td colspan="2" align="center" style="border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic">No Product Available</td>
</tr>
<?
}
} // while($rs
} // while($rs2
//mysql_free_result($result);
?>
</table>
<?
} // if($_SESSION["username"]==''){
?>
|
 |
 |
 |
 |
Date :
2013-05-28 13:46:09 |
By :
thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ Copy Code ที่ผมทำ เอาไว้ไป Run แล้ว เป็นอย่างไรบ้างครับ เหมือนเดิมหรือ? ขอดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2013-05-28 15:27:05 |
By :
thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ code แบบเต็มๆแล้วเหรอครับ เป็นไปได้ขอแบบเต็มๆครับ
|
 |
 |
 |
 |
Date :
2013-05-28 16:06:27 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา Code ด้านล่างนี้ไป ลอง Run ดูครับ มันต้องได้ครับ มันต้องได้ครับ
<table align="center" width="80%" height="130px" border="0" style="margin-top:10px;">
<?
$sql = "SELECT * FROM sp_type";
$qr = mysql_query($sql);
while($rs2 = mysql_fetch_array($qr))
{
echo "<tr>";
echo "<td colspan='2' align='center' style='font-family:'Times New Roman', Times, serif; font-size:16px; color:blue; border-bottom:1px solid #bbbbbb; padding-bottom:2px;'>".trim($rs2["name_type"])."</td>";
echo "</tr>";
if($_SESSION["lang"]!="th"){
echo "<tr>";
echo "<td align='left' style='color:black;'>Product Name</td>";
echo "<td align='left' style='color:black;'>Amount</td>";
echo "</tr>";
}
else{
echo "<tr>';
echo "<td align='left' style='color:black;'>ชื่อสินค้า</td>";
echo "<td align='left' style='color:black;'>จำนวน</td>";
echo "</tr>";
}
$id_type = $rs2["id_type"];
$i=0;
$sql = "SELECT sp_stock_import.part_id , sp_stock_import.part_name , sp_type.id_type , SUM(amount) AS Amount ";
$sql .= "FROM sp_stock_import ";
$sql .= "INNER JOIN sp_stock_list ON sp_stock_list.part_id = sp_stock_import.part_id ";
$sql .= "INNER JOIN sp_type ON sp_type.id_type = sp_stock_list.id_type ";
$sql .= "where sp_type.id_type=$id_type ";
$sql .= "GROUP BY sp_stock_list.part_id, sp_stock_import.part_name, sp_type.id_type";
while($rs=mysql_fetch_array($sql))
{
$i++;
echo "<tr>";
echo " <td align='left' style='border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic'>".$rs["part_name"]."</td>";
echo " <td align='left' style='border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic'>".$rs["Amount"]."</td>";
echo "</tr>";
}
if($i==0){
echo "<tr>";
echo "<td colspan='2' align='center' style='border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic'>No Product Available</td>";
echo "</tr>";
}
}
?>
</table>
|
 |
 |
 |
 |
Date :
2013-05-28 16:17:30 |
By :
thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<table align="center" width="80%" height="130px" border="0" style="margin-top:10px;">
<?
$sql = "SELECT * FROM sp_type";
$qr = mysql_query($sql);
while($rs2 = mysql_fetch_array($qr))
{
echo "<tr>";
echo "<td colspan='2' align='center' style='font-family:'Times New Roman', Times, serif; font-size:16px; color:blue; border-bottom:1px solid #bbbbbb; padding-bottom:2px;'>".trim($rs2["name_type"])."</td>";
echo "</tr>";
if($_SESSION["lang"]!="th"){
echo "<tr>";
echo "<td align='left' style='color:black;'>Product Name</td>";
echo "<td align='left' style='color:black;'>Amount</td>";
echo "</tr>";
}
else{
echo "<tr>';
echo "<td align='left' style='color:black;'>ชื่อสินค้า</td>";
echo "<td align='left' style='color:black;'>จำนวน</td>";
echo "</tr>";
}
$id_type = $rs2["id_type"];
$i=0;
$sql = "SELECT sp_stock_import.part_id , sp_stock_import.part_name , sp_type.id_type , SUM(amount) AS Amount ";
$sql .= "FROM sp_stock_import ";
$sql .= "INNER JOIN sp_stock_list ON sp_stock_list.part_id = sp_stock_import.part_id ";
$sql .= "INNER JOIN sp_type ON sp_type.id_type = sp_stock_list.id_type ";
$sql .= "where sp_type.id_type=$id_type ";
$sql .= "GROUP BY sp_stock_list.part_id, sp_stock_import.part_name, sp_type.id_type";
$result = mysql_query($sql);
while($rs=mysql_fetch_array($result))
{
$i++;
echo "<tr>";
echo " <td align='left' style='border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic'>".$rs["part_name"]."</td>";
echo " <td align='left' style='border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic'>".$rs["Amount"]."</td>";
echo "</tr>";
}
if($i==0){
echo "<tr>";
echo "<td colspan='2' align='center' style='border-bottom:1px dotted #bbbbbb; padding-bottom:2px; font-style:italic'>No Product Available</td>";
echo "</tr>";
}
}
?>
</table>
|
 |
 |
 |
 |
Date :
2013-05-28 16:22:00 |
By :
thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|