$strSQL0 = "SELECT * FROM customer WHERE Status = '0' ";
$objQuery0 = mysql_query($strSQL0) or die ("Error Query [".$strSQL0."]");
$numrows = mysql_num_rows($objQuery0);
if($numrows <= 0)
{
$strSQL00 = "UPDATE customer SET Status = '0' ";
$objQuery00 = mysql_query($strSQL00) or die ("Error Query [".$strSQL00."]");
}
code เต็ม ๆ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL0 = "SELECT * FROM customer WHERE Status = '0' ";
$objQuery0 = mysql_query($strSQL0) or die ("Error Query [".$strSQL0."]");
$numrows = mysql_num_rows($objQuery0);
if($numrows <= 0)
{
$strSQL00 = "UPDATE customer SET Status = '0' ";
$objQuery00 = mysql_query($strSQL00) or die ("Error Query [".$strSQL00."]");
}
$strSQL = "SELECT * FROM customer WHERE Status = '0' ORDER BY RAND() LIMIT 2 ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
$strSQL2 = "UPDATE customer SET Status = '1' WHERE CustomerID = '".$objResult["CustomerID"]."' ";
$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>