Closed Thread Icon

Topic awaiting preservation: switch & select: more than 3? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12334" title="Pages that link to Topic awaiting preservation: switch &amp;amp; select: more than 3? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: switch &amp; select: more than 3? <span class="small">(Page 1 of 1)</span>\

 
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 07-29-2002 11:05

Hola.
Stoopid question:
how many 'case' can I have into a switch statement??
I'm asking this because the script does not work when I add more than 3 select.
The script: <BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
switch($var) {
case "borrar":
$query_delete = "delete from espera where ID = " . $hola . " ";
$result_delete = mysql_query($query_delete, $link);
echo "mensaje eliminado<br> <a href=index.php>regresar a administración</a> <br><a href=../index.php>ir a contactos</a>";
break;

case "aceptar":
$query_darAlta = "INSERT INTO post SELECT * FROM espera WHERE ID = " . $hola . "";
$result_darAlta = mysql_query($query_darAlta) or die ("Could not query.");
$query_delete = "delete from espera where ID = " . $hola . " ";
$result_delete = mysql_query($query_delete, $link);
echo "mensaje agregado a los contactos<br> <a href=index.php>regresar a administración</a> <br><a href=../index.php>ir a contactos</a>";
break;

case "editar":
$query_select = "select nombre,pais,img1,thumb1,mensaje,email,categoria,img2,thumb2,img3,thumb3,img4,thumb4,ref,id from espera where ID = " . $hola . " ";
$result_select = mysql_query($query_select, $link);
$num_posts = mysql_num_rows($result_select);
while ($row = mysql_fetch_array($result_select)) {
echo "<TR bgColor=#444444>\n";
echo "<td align=left Valign=top width=150>\n";
echo "<b>".$row[0]."</b>\n";
echo "<br>".$row[1]."\n";
echo "<br><FORM action=update.php method=post><input type=text name=mail value=".$row[5].">\n";
echo "</td>\n";
echo "<td align=left Valign=top>Categoría:<b>
<select name=categoria size=1>
<option value='".$row[6]."' selected>".$row[6]."</option>
<option value='chica busca chica'>chica busca chica</option>
<option value='chica busca chico'>chica busca chico</option>
<option value='chica busca pareja'>chica busca pareja</option>
<option value='chico busca pareja'>chico busca pareja</option>
<option value='chico busca chico'>chico busca chico</option>
<option value='chico busca chica'>chico busca chica</option>
<option value='pareja busca pareja'>pareja busca pareja</option>
<option value='pareja busca chico'>pareja busca chico</option>
<option value='pareja busca chica'>pareja busca chica</option>
</select></b>

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-29-2002 11:37

in theory, your case can have as many conditions as you'd like to have.
hm, what does the script say when it 'breaks'?
I can't find anything wrong with it just glancing over it...

so long,

Tyberius Prime

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 07-29-2002 11:48

Sorry TB, My BAd. The error is this:
Parse error: parse error, unexpected T_DEFAULT in /httdoc/process.php on line 172


Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 07-29-2002 11:49

*forgots the edit buttom*

Oh, and the line error changes if I delete one select. Always point to the last'select'. And so until I leave just 3 selects

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-29-2002 12:15

You have a syntax error in the fourth case statement...

if (count($del) > 1) {
for ($i=0;$i<count($del);$i++) {
$result[$i] = mysql_query("DELETE FROM espera WHERE id = '$del[$i]'");
}
} <-- you forgot the closing bracket for if statement


Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 07-29-2002 12:20

Jheez, me and my stupids sintaxis mistakes!!!
I'm changing and testing!

(BRB)

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 07-29-2002 12:24

No, it doesn't work, even if I delete the complete 'case' statement.......
I have to delete 2 cases to make it work, looks like there's a limit (thought I've learned that cases have no limit)

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 07-29-2002 17:33

Yeah, but the } was missing in the second select

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-29-2002 17:34

Well, you have another syntax error in the third case statement ("editar"). You forgot to close while statement...


« BackwardsOnwards »

Show Forum Drop Down Menu