Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

could some expert here explain the meaning of these code?

Posted on 2009-02-19
10
Medium Priority
?
285 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:lilyyan
  • 5
  • 5
10 Comments
 
LVL 3

Assisted Solution

by:DavidSingleton
DavidSingleton earned 2000 total points
ID: 23682061
It's just creating an array of your database records.  I will say it looks like he is expecting numerous values in each field though.  I see no other reason to create arrays of Projtime, locations, or limit.  Do these fields store multiple values?

Anywhere else in the code you could print all info from the first record by doing:
print_r($projGroup[0]);

Open in new window

0
 

Author Comment

by:lilyyan
ID: 23682237
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
0
 

Author Comment

by:lilyyan
ID: 23682339
if print_r($projGroup[1]);

Array (
 [0] => Array ( [0] => Full Year )
[1] => Array ( [0] => city A)
 [2] => Array ( [0] => 5 )
 )
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
DavidSingleton earned 2000 total points
ID: 23682376
Each record is an array: IE: $projGroup[0] = record 1, $projGroup[1] = record 2 and so on.
Each Record array($progGroup[0]) contains a array with three values [0][1][2]  each value corresponds to a field 0 is projtime, 1 is location and 2 is limit.  

For some reason or the other, he's creating an array of the values in there also, making a third array

So then, lets say you wanted the location of the third record; (Remeber all arrays start at 0).  Here is what you would do.
/* WHERE 2 is the record number (The Third Record), 1 is the Field (The 
*Second Field) and 0 is the Field Entry (The First entry, or only entry in 
*this case)
*/
echo $projGroup[2][1][0];

Open in new window

0
 

Author Comment

by:lilyyan
ID: 23682970
what is the third array?

can it be simplyfied? it's really confused me.
0
 

Author Comment

by:lilyyan
ID: 23683017
and what this means: projGroup[$i][1] = explode("XX", $rw['LOCATIONS']);
0
 
LVL 3

Expert Comment

by:DavidSingleton
ID: 23683104
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

0
 
LVL 3

Assisted Solution

by:DavidSingleton
DavidSingleton earned 2000 total points
ID: 23683125
Sorry still no edit it should be:
while ($rw = mssql_fetch_assoc($rslt))
{
        $projGroup[] = array("PROJTIME" => $rw['PROJTime'],
                             "LOCATIONS" => $rw['LOCATIONS'],
                             "LIMIT" => $rw['LIMIT']);
}
 
#get values like this:
foreach($projGroup as $project)   {
   foreach($project 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

0
 

Author Comment

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

in my origional posted code
0
 
LVL 3

Assisted Solution

by:DavidSingleton
DavidSingleton earned 2000 total points
ID: 23683306
It means he was expecting numerous LOCATIONS in one database record.  for instace VALUE1XXVALUE2.  This was a way to get both of those values (seperated by XX) into one array.

explode takes two parameters, the first is a separator, the second is a string.

It creates an array out of the string by making the separator separate them.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question