Solved

could some expert here explain the meaning of these code?

Posted on 2009-04-07
5
218 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
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
<?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
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now