php - $c = mysql_num_rows(mysql_query($q)); -


i wondering if this

$c = mysql_num_rows(mysql_query("select * action_6_weekly code='$code'")); 

is considered valid php?

or need following?

$r = mysql_query("select * action_6_weekly code='$code'"); $c = mysql_num_rows($r); 

this doing:

if($entry == '9')     $c = mysql_num_rows(mysql_query("select * action_6_5pts code='$code'")) or die ('mysql error: '.mysql_error().' in '.__file__.' on '.__line__.'.'); elseif($entry == 'a')     $c = mysql_num_rows(mysql_query("select * action_6_10pts code='$code'")) or die ('mysql error: '.mysql_error().' in '.__file__.' on '.__line__.'.'); else     $c = mysql_num_rows(mysql_query("select * action_6_weekly code='$code'")) or die ('mysql error: '.mysql_error().' in '.__file__.' on '.__line__.'.');  if($c > 0)      $waiting_for_reply = false; 

it better on separate lines , assign variable.

this way can work result easier. count of rows, if looking for, better , more efficient:

$r = mysql_query("select count(id) action_6_weekly code='$code'"); $c = mysql_result($r, 0, 0);

where id unique identifier field count.

edit: given not care how many rows there are, exists:

$r = mysql_query("select code action_6_weekly code='$code' limit 1"); if (mysql_num_rows($r) > 0) {     // echo exists! } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -