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
Solved

could some expert here explain the meaning of these code?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Google Maps API and PHP 25 49
Display images from mysql blob type (Not working) 9 41
website maintenance mode 1 25
JQuery Search Filter 2 28
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

839 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