RE: [PHP-DB] switch and while
| From: | Emiliano Boragina | Date: | Fri, 28 Aug 2009 06:25:30 +0000 |
| Subject: | RE: [PHP-DB] switch and while | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46459@lists.php.net to get a copy of this message | ||
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@gmail.com /
// 15 40 58 60 02 ///////////////////////////
+
_
________________________________________
De: Arie Nugraha [mailto:dicarve@gmail.com]
Enviado el: Viernes, 28 de Agosto de 2009 03:13 a.m.
Para: Emiliano Boragina
Asunto: Re: [PHP-DB] 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@gmail.com> 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@gmail.com /
// 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