[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

could some expert here explain the meaning of these code?

Posted on 2009-04-07
5
Medium Priority
?
246 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              
<?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
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 24088556
<?php
/// include the code of this file into the current one.
/// -> this will eventually open a connection to the mssql database
include "dbConn.php";
 
/// define the sql to run.
/// note: the * should be replaced by PROJTIME, LOCATIONS, LIMIT  to reduce network traffic
$SQL = "SELECT * FROM ProjectGroups";
 
/// this runs the query, and the "cursor" id is hold by $rslt
$rslt = mssql_query($SQL);

/// initialize the row counter
$i = 0;

/// here should be this line, to initialize the variable that will hold all the data later:
$projGroup = array();

// now, loop on the rows returned, fetching 1 by 1
while ($rw = mssql_fetch_assoc($rslt))
{
      /// here should be this line, to initialize the array item as array itself
      $projGroup[$i] = array();

      // now, assign the row data into the array, taking the returned column data
      $projGroup[$i][0] = array($rw['PROJTIME']);
      $projGroup[$i][1] = explode("XX", $rw['LOCATIONS']);
      $projGroup[$i][2] = array($rw['LIMIT']);

      /// increment the row counter to prepare for the next loop iteration
      $i++;
}

/// this one is not needed in this code so far.
$i = 0;
?>
0
 

Author Comment

by:lilyyan
ID: 24099807
thanks for your reply!

would you please explain more detail for the following code?
how many demissions for $projGroup ?multiple dimension array make me really confused  :)
while ($rw = mssql_fetch_assoc($rslt))
{
      /// here should be this line, to initialize the array item as array itself
      $projGroup[$i] = array();
 
      // now, assign the row data into the array, taking the returned column data
      $projGroup[$i][0] = array($rw['PROJTIME']);
      $projGroup[$i][1] = explode("XX", $rw['LOCATIONS']);
      $projGroup[$i][2] = array($rw['LIMIT']);
 
      /// increment the row counter to prepare for the next loop iteration
      $i++;
}

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24100241
it's actually an single-dimension array, with the items being an array itself.
so, it's not a true multi-dimension array, but close to.
0
 
LVL 2

Assisted Solution

by:ozanhazer
ozanhazer earned 1000 total points
ID: 24107208
Actually It's a two dimensional array with the items being an array itself.
Think it as smt. like this:

You have "Project Groups" (named $projGroup). Each "Project Group" in that "Project Groups" has 3 properties:
0: Project time
1: Multiple locations
2: Limit

The trick is, project time and limit are converted to array. Normally there is no need to convert them to array but I guess that's something related with the rest of the code...

The following code is the same as above, maybe that would look more meaningful
while ($rw = mssql_fetch_assoc($rslt))
{
      $time      = array($rw['PROJTIME']);
      $locations = explode("XX", $rw['LOCATIONS']);
      $limit     = array($rw['LIMIT']);
 
      $projGroup[$i] = array($time, $locations, $limit);
      $i++;
}

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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
Course of the Month19 days, 19 hours left to enroll

873 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