?
Solved

could some expert here explain the meaning of these code?

Posted on 2009-04-07
5
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 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