PHP Classes

While inside the array

Recommend this page to a friend!

      MS-Excel Stream Handler  >  All threads  >  While inside the array  >  (Un) Subscribe thread alerts  
Subject:While inside the array
Summary:Fix error
Messages:7
Author:Hipolito Delgado
Date:2006-10-15 20:30:11
Update:2006-10-16 04:54:49
 

  1. While inside the array   Reply   Report abuse  
Picture of Hipolito Delgado Hipolito Delgado - 2006-10-15 20:30:11
How I can change this example:

=============== BEGIN
$assoc = array(
array("Sales Person" => "Sam Jackson", "Q1" => "$3255", "Q2" => "$3167", "Q3" => 3245, "Q4" => 3943),
array("Sales Person" => "Jim Brown", "Q1" => "$2580", "Q2" => "$2677", "Q3" => 3225, "Q4" => 3410),
array("Sales Person" => "John Hancock", "Q1" => "$9367", "Q2" => "$9875", "Q3" => 9544, "Q4" => 10255),
);
=============== END

to this:

=============== BEGIN
$assoc = array(
while ($row = mysql_fetch_array($result)){
array("First Name" => "".$row["nombre1"]."", "Last Name" => "".$row["lastname"]."", "Email" => "".$row["email"].""),
}
);
=============== END

Without this error:

=============== BEGIN
Parse error: parse error, unexpected T_WHILE, expecting ')' in /xxx/xxx/xxx/www/xxx/xxx.php on line xx
=============== END

  2. Re: While inside the array   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2006-10-16 00:59:00 - In reply to message 1 from Hipolito Delgado
You can't have a while {} declaration inside an array declaration. RTFM.

  3. Re: While inside the array   Reply   Report abuse  
Picture of Hipolito Delgado Hipolito Delgado - 2006-10-16 02:39:51 - In reply to message 2 from Ignatius Teo
Ok, but how I can change it using values from a table?

  4. Re: While inside the array   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2006-10-16 03:10:29 - In reply to message 3 from Hipolito Delgado

  5. Re: While inside the array   Reply   Report abuse  
Picture of Hipolito Delgado Hipolito Delgado - 2006-10-16 03:24:39 - In reply to message 4 from Ignatius Teo
but you just said I can't use while!

  6. Re: While inside the array   Reply   Report abuse  
Picture of Ignatius Teo Ignatius Teo - 2006-10-16 04:02:57 - In reply to message 5 from Hipolito Delgado
I give up... I don't know how to put this more delicately, so I'll be blunt. You need to learn how to program in PHP. I didn't say you couldn't use WHILE. I said you can't use a WHILE declaration INSIDE an array declaration. It's not valid syntax - in ANY language.

RTFM = Read The Frigging Manual.

Please don't submit any more posts to this forum regarding this issue. This is a programming issue with YOUR code. I don't provide free support. But for a small fee, I can fix it for you.


  7. Re: While inside the array   Reply   Report abuse  
Picture of Hipolito Delgado Hipolito Delgado - 2006-10-16 04:54:49 - In reply to message 6 from Ignatius Teo
In my first message I show the code I'm using and the error. But thanks anyway for your help.