Hi All,

Im accessing a function with paticular parameters, but my response is not recognising the parameter of the count value.

If I change the variable in the COUNT part of the query to a static value it works fine, but if i use the variable name it returns "undefined index".

Any help would be greatly appreciated

class answers {

    function totals($questionName, $startdate, $enddate, $advisor){
      $SQL = "SELECT COUNT($questionName) FROM interview_answers i, accounts a WHERE a.client_id = i.client_id AND advisor = '$advisor' AND sesdate>= '$startdate' AND sesdate<='$enddate'";
      $result = mysql_query($SQL);
      $row = mysql_fetch_assoc($result);
      echo $totalresponses = $row['COUNT($questionName)'];



That's a simple one. Just add the clause " AS questioncount " immediately after the COUNT keyword.
ie. SELECT COUNT($questionName) AS questioncount FROM interview_answers ... Then in line 9 use the code: echo $totalresponses = $row['questioncount'];

perfect, thank you very much. i should have known that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.