0

I am getting a Resource id # as a result. The query returns the right count when using myphpadmin. I have tried using mysql_fetch_assoc, and mysql_fetch_row but I can't get it to work. Could use some guidance. Thank you.

note: $casenumber reflects the case number from a different table

$casenumber= ($rows['case_number']);  //stores this rows case number

$casecount = "SELECT COUNT(case_number) AS `total`  
FROM `vekt6_chronoforms_data_CaseJuryPool`\n"
    . "WHERE vekt6_chronoforms_data_CaseJuryPool.case_number = '{$casenumber}'";

$num = mysql_query($casecount);

echo $num; // result of case numbers count
Craig Martin
  • 161
  • 1
  • 1
  • 12

1 Answers1

3

You forgot to fetch your results

$res = mysql_query($casecount);
$row = mysql_fetch_assoc($res);
echo $row['total'];

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • That worked. I have a similar problem with the query below. It echos the word Array instead of a number. $uniquejuror = "SELECT COUNT(`case_number`) AS `total2` FROM `vekt6_chronoforms_data_CaseJuryPool` WHERE `vekt6_chronoforms_data_CaseJuryPool.case_juror` = '{$uid}'; AND `vekt6_chronoforms_data_CaseJuryPool.case_number` = '{$casenumber}'"; $uj = mysql_query($uniquejuror); $rowuj = mysql_fetch_assoc($uj); echo $rowuj['total2']; – Craig Martin Sep 23 '13 at 09:43