Jump to content

Switch php


klasss
 Share

Recommended Posts

Bom dia a todos,

Estou com um problema com um switch no php pois da-me um erro no fim

if (isset($_POST['estado']) || ($_POST['Distrito']) || ($_POST['Concelho']))
{
switch([$_POST['estado'] , $_POST['Distrito'], $_POST['Concelho']])
{
case ['Indiferente','Indiferente','Indiferente']:
$sql = Query....
$qr = mysql_query($sql) or die(mysql_error());
break;
(...)
}
}
$qr = mysql_query($sql) or die(mysql_error());
while($exibe = mysql_fetch_array($qr)){
echo "<table>";

Notice: Undefined variable: sql

Obrigado

Link to comment
Share on other sites

http://www.php.net/manual/en/control-structures.switch.php

The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.

IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

O meu problema e mostrar o resultado no fim do Switch.

O outro acabei por corrigir

case ['Indiferente','Indiferente','Indiferente']:
$sql = Query....
$qr = mysql_query($sql) or die(mysql_error());
break;
(...)
}
}
$qr = mysql_query($sql) or die(mysql_error());
while($exibe = mysql_fetch_array($qr)){
echo "<table>";
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.