Link to home
Start Free TrialLog in
Avatar of lilyyan
lilyyan

asked on

could some expert here explain the meaning of these code?

Hello:
could some expert here explain the meaning of these code? the more detail , the better
thank you so much for your reply!

The DB table for the php code

PROJTIME               LOCATIONS   LIMIT
Fall 2009                  city A              5
Full year                   city A              5
Summer 2009           city A              5
<?php
include "dbConn.php";
 
$SQL = "SELECT * FROM ProjectGroups";
 
$rslt = mssql_query($SQL);
 
$i = 0;
while ($rw = mssql_fetch_assoc($rslt))
{
	$projGroup[$i][0] = array($rw['PROJTIME']);
	$projGroup[$i][1] = explode("XX", $rw['LOCATIONS']);
	$projGroup[$i][2] = array($rw['LIMIT']);
	$i++;
}
$i = 0;
?>

Open in new window

SOLUTION
Avatar of DavidSingleton
DavidSingleton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lilyyan
lilyyan

ASKER

it return:
Array (
[0] => Array ( [0] => Fall 2009 )
[1] => Array ( [0] => city A )
[2] => Array ( [0] => 5 )
 )

could you please draw a matrix for me as i'm stll confused
Avatar of lilyyan

ASKER

if print_r($projGroup[1]);

Array (
 [0] => Array ( [0] => Full Year )
[1] => Array ( [0] => city A)
 [2] => Array ( [0] => 5 )
 )
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lilyyan

ASKER

what is the third array?

can it be simplyfied? it's really confused me.
Avatar of lilyyan

ASKER

and what this means: projGroup[$i][1] = explode("XX", $rw['LOCATIONS']);
The third array is the actual value of the field so it goes like this:
$projGroup[recordnum][field][value]

It could be simplified, assumming you only have one location, one time and one limit per each record in the database.

I would do something like this:


while ($rw = mssql_fetch_assoc($rslt))
{
        $projGroup[] = array("PROJTIME" => $rw['PROJTime'],
                             "LOCATIONS" => $rw['LOCATIONS'],
                             "LIMIT" => $rw['LIMIT']);
}
 
#get values like this:
foreach($projGroup as $key => $val)   {
   echo $key . ": " . $val . '<br />';
}
 
#or to get a specific field of a record:
$recnum = 1;
echo $projGroup[$recnum]["LOCATIONS"];

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lilyyan

ASKER

also what this means: projGroup[$i][1] = explode("XX", $rw['LOCATIONS']);

in my origional posted code
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial