RE: switch and while

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Arie?
But I need to do "category1" be the ID of my table.
Using this way I have CASE number_ID_table echo string_CATEGORY_FIELD_table,
and will be automatic... Many CASES as ID I having in the database

Thanks again

+                                                                          _
   // Emiliano Boragina _
   // Diseño & Comunicación //////////////////
+                                                                          _
   // emiliano.boragina@xxxxxxxxx  /
   // 15 40 58 60 02 ///////////////////////////
+                                                                          _
________________________________________
De: Arie Nugraha [mailto:dicarve@xxxxxxxxx] 
Enviado el: Viernes, 28 de Agosto de 2009 03:13 a.m.
Para: Emiliano Boragina
Asunto: Re:  switch and while

You have wrong syntax there :

The switch construct is working like this :

<?php

switch ($selectCategory) 
{
    case 'category1':
        while ($array=mysql_fetch_array($resultCat)) {
            // do something here
        }
    break;
    case 'category2':
    // do another thing
    break;
}

?>

Or maybe what you mean is like this :

while ($row=mysql_fetch_array($resultCat)) {
    switch ($row[0]) {
        case 'category1' :
           // do something here
        break;
        case 'category2' :
            // do something here
        break;
    }
}

On Fri, Aug 28, 2009 at 1:03 PM, Emiliano Boragina
<emiliano.boragina@xxxxxxxxx> wrote:
Hello.

I want do a SWITCH using data base MySQL.
The CASE must be a variable, same the ECHO.
My table (CATEGORY) contain ID and NAME

I do this (with a WHILE):

$sqlCat = "SELECT * FROM categoria";
$resultCat = mysql_query($sqlCat);

switch ($selectCategory)
{
       while($array=mysql_fetch_array($resultCat))
       {
      case $row[0]:
               $categoy = "$row[1]";
               break;
       }
}

But doesnt works, print an error: Parse error: syntax error, unexpected
T_WHILE, expecting T_CASE or T_DEFAULT or '}' in
C:\AppServ\www\andademiparte\admin\listado.php on line 118... this line is
the WHILE.

How can resolve this?
thanks

+                                                                          _
   // Emiliano Boragina _
   // Diseño & Comunicación //////////////////
+                                                                          _
   // emiliano.boragina@xxxxxxxxx  /
   // 15 40 58 60 02 ///////////////////////////
+                                                                          _



-- 
Open Source is about respecting other people creation and sharing knowledge
to others.
Sebaik baiknya manusia adalah yang bermanfaat bagi orang lain.
http://dicarve.blogspot.com


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux