Solved

could some expert here explain the meaning of these code?

Posted on 2009-04-07
5
222 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 250 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 250 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

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!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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