2014-10-29 134 views
0
<?php 
$con = mysql_connect('localhost', 'root', 'pass'); 
if(!$con){ 
echo "Error connection"; 
} 
$select_db = mysql_select_db('mydatabase', $con); 
if(!$select_db){ 
echo "Error to select database"; 
} 
mysql_set_charset("utf8", $con); 

$result = mysql_query("select count(1) FROM Credit WHERE CreditStatusID=6"); 
$row = mysql_fetch_array($result); 

$total = $row[0]-1; 
echo "<font size='6px' color='#000000'>Total:&nbsp;</font><font size='6px' color='#FF0000'><b>" . $total . "</b></font>"; 
mysql_close($con); 
?> 

我需要得到一些其他信息,例如WHERE CreditStatusID=6 AND CreditStatus=7,8,9,..,但它不起作用。你能解釋我怎樣才能以另一種方式做到這一點?選擇多個ID

回答

0

嘗試:

select count(1) FROM Credit WHERE CreditStatusID=6 and CreditStatus in (7,8,9) 
+0

我試過這種方式,但沒有結果: $ result = mysql_query(「select count(1)FROM Credit WHERE CreditStatusID = 6 AND CreditStatus in(1,2,3)」); – Levan 2014-10-29 07:26:16

+0

沒有結果請幫忙:( – Levan 2014-10-29 07:31:32

+0

請問您可以粘貼您的表格內容嗎? – SMA 2014-10-29 07:33:27

0

的WHERE子句應該是這樣的:

...WHERE CreditStatusID=6 AND CreditStatus IN (7, 8 ,9); 

而非陣列 「(7,8,9)」,你也可以使用一個子選擇...