Okay, so having seen a screenshot of the data in your table, things are clear why your initial query was finding no results. Your initial query was:
SELECT id, question
FROM polls
WHERE DATE(NOW())BETWEEN starts AND ends
So let’s dissect your WHERE clause. The NOW() function provides the current time with an accuracy of seconds, like this: 2014-09-09 21:57:24. Now when this value is wrapped in the DATE() function, the accuracy drops to days (effectively truncating the value). So the aforementioned NOW() value would look like the following when passed into DATE(): 2014-09-09.
Next we have the BETWEEN clause which will perform a check that the left hand operand (our 2014-09-09) is between the specified start and end date (inclusive). Now looking at your two records, your start dates are both 2014-09-05, however your end dates are before both of your start dates, which means that you will never find any dates that start from 2014-09-05 to 0000-00-00. If you switched the two dates around, then you’ll find plenty of dates (including your DATE(NOW()) function).
–
Now you keep asking about your error message (which is actually simply a notice): Notice: Undefined variable: polls in C:\xampp\htdocs\pollPhp\index.php on line 11
As explained in my first post, the problem is with the following:
while($row = $pollsQuery->fetchObject()){
$polls[] = $row;
}
If your query finds no results (and it didn’t, for the aforementioned), then the condition of your while loop ($row = $pollsQuery->fetchObject()) will return false, and your while body ($polls = $row;) will not execute. This means that the $polls variable will never be created, and thus will produce a warning when you try to use it in the following line:
echo '<pre>', print_r($polls) ,'</pre>';
The solution would be to define the $polls variable above the while loop, so that in case your query does not find any results, your $polls variable will still be defined (albeit as an empty array).
I hope that clears everything up - just let me know if you need anything else explained.