Musíte změnit typ pole v while smyčka. mysql_fetch_array
vrátí standardní pole přístupné jako $array[0] ne $array['my_key'] takže použijte mysql_fetch_assoc
.
Takže místo toho:
while ($results = mysql_fetch_array($raw_results)) {
echo "<p><strong>Never:</strong> <span id=\"nevermsg\">".$results['Never']."</span></p>"; //Doesn't
}
Udělejte toto:
while ($results = mysql_fetch_assoc($raw_results)) {
echo "<p><strong>Never:</strong> <span id=\"nevermsg\">".$results['Never']."</span></p>"; //Works
}
AKTUALIZACE :
Další možnost, pokud neznáte key je smyčka přes $results samotné pole jako takové s foreach
:
while ($results = mysql_fetch_assoc($raw_results)) {
foreach ($results as $key => $value) {
echo "<span id=\"nevermsg\"><p><strong>$key:</strong> ".$value."</p></span><br/>";
}
}
Podívejte se na příklad PHP houslí smyčky a <span> v akci zde
. Z pochopitelných důvodů nebylo možné SQL duplikovat v houslích.