|
|
|
PHP Mysql นับจำนวน record ที่ซ้ำกันมาแสดงเพียงครั้งเดียวและนับจำนวนที่ซ้ำ |
|
|
|
|
|
|
|
Code (SQL)
SELECT NAME, COUNT(DeviceID) AS QTY FROM tb_name GROUP BY NAME
|
|
|
|
|
Date :
2017-01-10 14:40:33 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือก่อนหน้านี้ผมใช้โคตรแบบนี้อะครับ
Code (PHP)
<?php require_once('Myconnection.php'); ?>
<?php session_start();
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
} mysql_select_db($database_Myconnection, $Myconnection);
$sqlobject = "UPDATE user SET Lastupdate = NOW() WHERE UserID = '".@$_SESSION["UserID"]."' ";
$queryobject = mysql_query($sqlobject,$Myconnection);
$num = 0;
$strSQL = "SELECT * FROM `equipment`";
$equipmentQuery = mysql_query ($strSQL,$Myconnection) or die ("Error Query [".$strSQL."]");
if(@$_SESSION["username"]==""){
echo '<script language="javascript">
function fncAlert()
{
alert(" กรุณา Login เข้าสู่ระบบก่อน ");
}
fncAlert();
window.location="index.php";
</script>';
}
session_write_close();
?>
<!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>TableEquipment</title>
</head>
<body>
<table width="50%" align="center" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="10%"><div align="center">ลำดับ</font></div></td>
<td width="60%"><div align="center">รายชื่ออุปกรณ์</font></div></td>
<td width="10%"><div align="center">จำนวน</font></div></td>
</tr>
<?php while($equipmentResult = mysql_fetch_array($equipmentQuery)){?>
<?php $num++;?>
<tr>
<td><div align="center"><?php echo $num;?></font></div></td>
<td> <?php echo $equipmentResult["Name"];?></font></td>
</tr>
<?php } ?>
</table>
</body>
<?php mysql_close($Myconnection); ?>
</html>
แล้วพอแสดงมันก็จะแสดงออกมาแบบนี้อะครับ
|
|
|
|
|
Date :
2017-01-10 14:58:15 |
By :
blackjome |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับขอบคุณครับ
|
|
|
|
|
Date :
2017-01-10 16:45:36 |
By :
blackjome |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DINTINCT
COUNT
GROUP BY
|
|
|
|
|
Date :
2017-01-10 17:17:51 |
By :
limberger |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2017-01-11 13:07:02 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|