• Welcome to Valhalla Legends Archive.
 

Help with dynamic Switch cases

Started by FrostWraith, October 29, 2006, 02:35 PM

Previous topic - Next topic

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!

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;
}
}

Warrior

Try something like this:


while ($row = mysql_fetch_array($result))
{
if ($row['id'] == $page)
{
echo $row['title'];
}
}
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

rabbit

On a completely unrelated note, you should cast $page to an int.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

FrostWraith

#3
Thank you both for your input. Problem solved.

@Rabbit: I do.

Warrior

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.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Warrior

Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?