 |
ขอความช่วยเหลือเรื่องของการ sum จำนวนที่ซ้ำกันหน่อยค่ะ |
|
 |
|
|
 |
 |
|
sum คือ รวม count คือ นับ สรุปว่าเอา อันไหนครับ sum หรือ count ครับ
ถ้าจำไม่ผิด ประมาณนี้ครับ
Code (PHP)
<?php
// count
$sql="select count(*) from table "
// sum
$sql="select sum(fild) from table ";
?>
|
 |
 |
 |
 |
Date :
2009-07-15 14:05:58 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทั้ง 2 อย่างค่ะ
|
 |
 |
 |
 |
Date :
2009-07-15 14:31:17 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ทำได้ในระดับหนึ่งค่ะ แต่ถว่าปัญหาก้อมีมาด้วย
เราต้องการค้นหาโดยใช้ชื่อค่ะ แต่เราใช้การเรียก recode ชื่อมาจากไฟล์อื่นแบบนี้อ่ะค่ะ
<?
//ผู้เปิดบิล
$fnametype[1]="พรนธี ( มด )";
$fnametype[ ]="ขวัญเรือน ( ขวัญ )";
$fnametype[ ]="สุพิดา( แหม่ม )";
$fnametype[ ]="ถาวร ( แจ็ค )";
$fnametype[ ]="มณีรัตน์ี ( หมวย )";
$fnametype[ ]="รัตนา ( ปุุ๊ย )";
$fnametype[ ]="อัญชลี ( เกด )";
$fnametype[ ]="ประสิทธิ์ ( เอ้ )";
$fnametype[ ]="ประพันธ์ ( พันธ์ )";
$fnametype[ ]="ประเทือง ( อาร์ท )";
$fnametype[ ]="เอกชัย ( เอก )";
$fnametype[ ]="สมคิด ( เทียม)";
$fnametype[ ]="ผู้จัดการ";
$fnametype[ ]="นันท์นภัส ( เจน)";
$fnametype[ ]="นริษา ( อ้อ )";
//ผู้หยิบ
//$nametype[1]="รอผู้หยิบ";
$nametype[1]="สมชื่น (ชื่น)";
$nametype[ ]="สมคิด (เทียม)";
$nametype[ ]="ทวี (วี)";
$nametype[ ]="สมชาย (ไก่)";
$nametype[ ]="อรุณ (เบาหวิว)";
$nametype[ ]="ศรันย์ (เอก)";
$nametype[ ]="ณัฐพล (กบ)";
$nametype[ ]="ประสิทธิ์ (เอ้)";
$nametype[ ]="ประเทือง (อาร์ท)";
$nametype[ ]="วุฒิกร (ท๊อป)";
$nametype[ ]="ตะวัน (ต้อม)";
$nametype[ ]="นพดล (แบงค์)";
$nametype[ ]="สมนึก (นึก)";
$nametype[ ]="ผู้จัดการ";
//สถานะ
//$statustype[1]="รอผู้หยิบ";
$statustype[1]="กำลังหยิบ";
$statustype[ ]="หยิบเสร็จรอเช็ค";
/*$statustype[ ]="รอแก้บิล";
$statustype[ ]="เช็คเสร็จรอแพ็คหน้าร้าน";
$statustype[ ]="เช็คเสร็จรอแพ็คหลังร้าน";
$statustype[ ]="แพ็คเสร็จรอส่งหน้าร้าน";
$statustype[ ]="แพ็คเสร็จรอส่งหลังร้าน";
$statustype[ ]="เสร็จแล้ว";
$statustype[ ]="ยกเลิก";*/
function displaydate($x) {
$date_m=array("01.","02","03","04","05","06","07","08","09","10","11","12");
$date_array=explode("-",$x);
$y=$date_array[0]+543;
$m=$date_array[1]-1;
$d=$date_array[2];
$m=$date_m[$m];
$displaydate="$d-$m-$y";
return $displaydate;
}
?>
เสดแล้วพอมาทำค้นหามานเลยเปงแบบนี้ค่ะแทนที่จะหาตามชื่อมานกลับหาตามเลขค่ะ
<html>
<head>
<title></title>
</head>
<body>
<form name="frmSearch" method="get" action="<?=$name_status['name_status'];?>">
<table width="60%" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?
if ($_GET["textKeyword"] != " ")
{
include "connect.php";
$objDB=mysql_select_db("db_alai");
$sql = "select * from alai where name_status like '%" . $_GET['txtKeyword'] . "%'";
$objQuery = mysql_query($sql) or die(mysql_error());
?>
<table width="60%" border="1">
<tr>
<th width="5%"><div align="center">ชื่อผู้หยิบ</div></th>
<th width="5%"><div align="center">จำนวน บิลที่หยิบ</div></th>
</tr>
<?
//echo mysql_num_rows($objQuery);
while ($objResult=mysql_fetch_array($objQuery))
$name_status=$r[name_status];
{
?>
<tr>
<td><div align="center"><?=$objResult["name_status"]?></div></td>
<td><div align="center"><? echo mysql_num_rows($objQuery) ?></div></td>
</tr>
<?
}
?>
</table>
<?
mysql_close();
}
?>
</body>
</html>
ผลลัพธ์มานก้อเลยออกมาเปงแบบนี้อ่ะ

แล้วเราจาแก้ไงดี
|
 |
 |
 |
 |
Date :
2009-07-15 17:56:44 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จริงๆ ข้อมูลข้างบนในตัวแปร ควรอยู่ใน database แล้วเอามาติ๊กชิโร่ 
ใครก็ได้ช่วยตบมุขให้ผมที 
|
 |
 |
 |
 |
Date :
2009-07-15 21:28:00 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
555+ มีหาพวก
|
 |
 |
 |
 |
Date :
2009-07-16 10:20:51 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอามา จอย ซินะ ๕๕๕+ 
มาม๊ะ มาจอยกัน มาจอยกัน
แหม ตอนนั้น ผมยังเด้กอายุ 6 ขวบเลยอะ ยังจำได้
|
 |
 |
 |
 |
Date :
2009-07-16 12:01:38 |
By :
danya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
..............ชาย...หญิง...รวม
น้ำหนาว....7........4......9
วังโป่ง...... 5........6.......11
เขาค้อ...... 4.......2.......6
------------------------------------------
รวม..........16.......12......26
------------------------------------------
ต้องการทราบว่า วิธีการทำผลรวม ทั้ง แถว และ คอลัมภ์ ต้องเขียนอย่างไรครับ ตารางนี้ได้จากการ Count(id) จากตาราง
|
 |
 |
 |
 |
Date :
2010-03-16 13:42:50 |
By :
แหลมทอง |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|