Valhalla Legends Forums Archive | Web Development | Help with dynamic Switch cases

AuthorMessageTime
FrostWraith
OK. In a database I have an ever changing index. I need it to generate a page for each one, like so:
index.php?page=1 , index.php?page=2

Is this a good way of going about this. I always get Unexpected T_CASE. I can't seem to get it to work!
[code]
if (isset($_GET['picture'])) {
$page=$_GET['picture'];
} else {
$page=0;
}
switch ($page) {
default:
    echo "none";
break;
while($row = mysql_fetch_array($result)) {
case $row['id']:
    echo $row['title];
break;
}
}[/code]
October 29, 2006, 8:35 PM
Quarantine
Try something like this:

[code]
while ($row = mysql_fetch_array($result))
{
if ($row['id'] == $page)
{
echo $row['title'];
}
}
[/code]
October 29, 2006, 8:40 PM
rabbit
On a completely unrelated note, you should cast $page to an int.
October 29, 2006, 8:52 PM
FrostWraith
Thank you both for your input. Problem solved.

@Rabbit: I do.
October 29, 2006, 9:02 PM
Quarantine
You could probably get away with the way you did above with output buffering and eval, it would of been ugly though. As ugly as rabbit.
October 29, 2006, 9:13 PM
rabbit
Below the belt, Mr. Mexican.
October 29, 2006, 11:18 PM
Quarantine
Hahaha <3.
October 30, 2006, 12:40 AM

Search