I have a database and I want to count the number of times a state shows up in it. I wanted to use this number later for calculations. However, when I try to do something like this (which correctly gives me '1' when I execute it in phpmyadmin):
(on controller) $sql = "SELECT count(state) FROM survey where state=\'New York\'";
(on view page) <?php echo $sql?>
I get this:
Notice: Undefined variable: sql in /home/ubuntu/workspace/[NAME]/views/results_form.php on line 3
Removing the backslashes made no difference. The structure of my database is like this (gender is a boolean):
- id - state - gender
- 1 - Florida - 1
- 2 - New York - 0
I think that the query is not even able to reach the database at all, if that makes sense. I imported tables from pset7 into phpmyadmin and tried to use one of the queries from pset7, and I got the same error. I'm not sure how to fix it if that's the case.