-5

I am trying to excute one mysql query in php.

$data=mysql_query("select distinct t_emp,count(t_emp), (select count(t_tittle) from task_data where status='Task completed' AND t_emp=a.t_emp)from task_data a group by t_emp");
while($test=mysql_fetch_array($data)){
}

I am getting below error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/70/11725470/html/dhamutest.php on line 5

gen_Eric
  • 214,658
  • 40
  • 293
  • 332
dhamu
  • 1
  • 1
  • 4
  • Your query is failing. But you're not checking for that, and assuming everything is working fine - a call to `mysql_error()` will show you what the issue is. – andrewsi Nov 08 '13 at 14:43
  • Only uncool kids still use `mysql_*` these days, as it is totally outdated. Do you want to be uncool ? Have a look into [this tutorial](http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/) to become cool again. It will make your coding life much better! – Sliq Nov 09 '13 at 00:20

2 Answers2

1

Please format your message and use code markups.

The problem is that your query is not well-formed, so mysql_query return boolean false.

Change

select distinct t_emp,count(t_emp), (select count(t_tittle) from task_data where status='Task completed' AND t_emp=a.t_emp)from task_data a group by t_emp

To

select distinct t_emp,count(t_emp), (select count(b.t_tittle) from task_data b where b.status='Task completed' AND b.t_emp=a.t_emp) AS T_LITTLE_COUNT from task_data a group by t_emp

The problem is that you used no alias for your table subquery, and that your subquery result has no name.

BTW, there's no database ressource given to mysql functions, read your documentation again. And you can use mysql_error to get the SQL analyser to tell what what's wrong in your queries (mysql's one is not always accurate...)

OlivierH
  • 3,817
  • 1
  • 18
  • 30
0

Both your queries are missing the database resource as parameter- check your required parameters against PHP docs.

andig
  • 12,720
  • 11
  • 56
  • 89
  • 5
    You don't need the database resource with `mysql_query` - if there's none given, it works with the most recently opened connection as a default. – andrewsi Nov 08 '13 at 14:45