0

So I wan to turn off the warning error I may get when doing this code.

for ($i=0; $i < count($project_array); $i++) { 

  $projecthours[$i] = project_hours($project_array[$i]);
  $project_name = $project_array[$i];

  $impact_query = "SELECT * FROM impact_data WHERE project_name ='$project_name'";
  $impact_search = mysql_query($impact_query);
  $impact_num = mysql_num_rows($impact_search);


  if ($impact_num > 0 ) {

          // Do something

  } //IMPACT_NUM IF 

  else {

      Do Something Else

  } // ELSE statement

Even though I've put the @ sign infront of both functions I still get the following error. I don't want to turn of all errors for the page because I think it is a bad idea, and I am still working on the website. Here is the warning I still get.

Warning: mysql_num_rows() expects parameter 1 to be resource

grasshopper
  • 878
  • 2
  • 13
  • 29
  • Why don't you just check your results instead of hiding errors? – Barmar Jan 16 '14 at 05:15
  • You can't turn off a warning from the php in the code, you'd have to do this in php.ini. You should re-do your coding to work around this error so that the sql statement can execute. what comes before the block of code you supplied? – iam-decoder Jan 16 '14 at 05:15
  • Why should the resource be a number? It should be a resource. – Barmar Jan 16 '14 at 05:16
  • I just want to check if any of those project names are in the database. How else can I do that? If they are i want it to do this if not do something else. – grasshopper Jan 16 '14 at 05:19
  • @iamde_coder it is just a function I wrote has nothing to do with the query. – grasshopper Jan 16 '14 at 05:21

2 Answers2

0

I think this helps you:

error_reporting(0);
$impact_num = @mysql_num_rows($impact_search);
error_reporting(E_ALL);`

Who says that it impossible? PHP is very flexible. =)

Emilio Gort
  • 3,450
  • 3
  • 28
  • 44
Pragmatist
  • 16
  • 2
  • haha the errors are actually gone so it works, but I put it before the for loop starts instead because one error would still show up. – grasshopper Jan 16 '14 at 05:31
0

How about to check $impact_search first

if(is_resource($impact_search))
{
    $impact_num = mysql_num_rows($impact_search);
    // Remaining stuff here
}
Hassan
  • 732
  • 7
  • 13