2013-07-24 57 views
0

不同的表計數行,我想我之前做過這樣的事情:在同一查詢

$reg = mysql_query ("(SELECT count(*) from vouchers) as total_vouchers), 
        (SELECT count(*) from vouchers WHERE asignado = 1) as vouchers_asignados, 
        (SELECT count(*) from crm) as crm_users, 
        (SELECT count(*) from datos_modificados) as dm_users") or die(mysql_error()); 

但它會返回附近的第一, mysql_error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as total_vouchers), ((SELECT count(*) from vouchers WHERE asignado = 1) a' at line 1 

任何想法,爲什麼?

回答

3

嘗試添加select如下

$reg = mysql_query ("SELECT 
        (SELECT count(*) from vouchers) as total_vouchers, 
        (SELECT count(*) from vouchers WHERE asignado = 1) as vouchers_asignados, 
        (SELECT count(*) from crm) as crm_users, 
        (SELECT count(*) from datos_modificados) as dm_users") or die(mysql_error());