An example, eh? Lessee…. Replace your entire code with this:
<?php
global $DB;
$query = $DB->query("SELECT MAX(poll_id) AS 'maxPoll' FROM exp_eepoll");
if ($query->num_rows > 0)
{
$currPoll = $query->row['maxPoll'];
}
else
{
$currPoll = 0; // this sets it to zero if there are no polls--so nothing is displayed
}
echo $currPoll; // This is a test to see if we got it right. Should kick out at the moment 75.
while ($currPoll > 0)
{
echo '{exp:eepoll poll_id="' . $currPoll . '"}{poll}{/exp:eepoll}';
$currPoll = $currPoll - 1;
}
?>
Set php on input.
I figured out what was going on with your original code—you ran into a loop that never ends, and php timed out or shorted it out at some point.
What happened is that when you dropped into PHP, you never got the value 75 into the php code. What you did was set the currPoll variable to a string, not an integer. currPoll was set to the string “{maxPoll}”—including the braces. It was then echoed to the rest of the screen. I’ll bet that with php on input, it translated it into 75—because EE saw the php output, which was “{maxPoll}” and inside the query module tag, it saw that as a variable, so it replaced it with the value of that variable, 75. But php never got the integer. So inside your while loop, it never had a number to subtract, only the string “{maxPoll}” And subtracting one from that is rather interesting, to say the least. It shows that when you hard coded an integer to the variable currPoll, it works—so you didn’t have a valid integer.
My code above will do what you want, and it should work. The only thing left is that you don’t have any html coding—no paragraph tags, etc. So change the echo inside the while loop. (BTW, when you take it live, get rid of the echo currPoll line above the while loop… it doesn’t do any good—just debugging code. )
You can do something like this:
...
echo '
{exp:eepoll poll_id="' . $currPoll . '"}{poll}{/exp:eepoll}</br>';
or other such like code.
Hope that helps!