2014-02-16 57 views
0

我想尋求一些幫助,我在php中查詢問題...我想要做的就是統計所有(atic)與相同的數字,如果具體(atic)等於7我插入查詢將執行到(atic)。在php中計數查詢

問題是我的數查詢不會工作,因爲我想....並執行我的插入查詢到所有AIC連計數不= 7

enter image description here

當前代碼:

<?php 
mysql_connect("localhost","root","") or die("cant connect!"); 
mysql_select_db("klayton") or die("cant find database!"); 
$total = NULL; 
$count = "SELECT count(t.atic) as '$total', t2.name FROM app_interview as t, tb_applicants as t2 WHERE t.atic = t2.aic GROUP BY t.atic"; 
$query = mysql_query($count) or die (mysql_error()); 
while($rows =mysql_fetch_array($query)){ 
if($query = 7){ 
    mysql_query("INSERT INTO afnup_worksheet (faic,fnl_name,interview,fregion,ftown,funiq_id,fposition,fsalary_grade,fsalary,dateinputed) SELECT DISTINCT atic, atname,(SELECT sum(inttotal) FROM app_interview t2 WHERE t2.atic = t.atic)/7, region, town, uniq_id, position, salary_grade, salary, CURRENT_TIMESTAMP FROM app_interview t GROUP BY atname HAVING COUNT(DISTINCT atic)"); 
} 
} 
?> 
+1

第一所有使用'if($ query == 7)'而不是'if($ query = 7)' – ponciste

回答

0

$query = 7意味着你要變$query

分配值7爲了比較,你必須使用雙等號==

或三重等號===對於相同的數據類型。

+0

我現在改爲==但我的查詢不會過濾特定的(atic)如果它= 7 ...你能幫忙嗎我和這個? – user3311499

+0

mick總共7(aic)應該執行,但它沒有按我的計劃工作。 – user3311499

+1

對不起,我不是一個真正的SQL專家。 'SELECT count(t.atic)'爲'$ total''爲什麼你把Total這樣 – meda

0
if($query = 7) 

意味着你指定$查詢是7,它會永遠真實,總是被執行,你可以試試這個

if($query == 7) 

這意味着,如果$query值等於7或不