Jump to content


Photo

please explain


  • Please log in to reply
10 replies to this topic

#1 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 05 October 2006 - 03:51 PM

what this means? I get it as output from

while ($subscription = mssql_fetch_array($res3)) {
                                                print_r($subscription);
                                        }

Array ( [0] => 0 [MarketID] => 0 )
Array ( [0] => 14 [MarketID] => 14 )
Array ( [0] => 9 [MarketID] => 9 )
Array ( [0] => 18 [MarketID] => 18 )
Array ( [0] => 1 [MarketID] => 1 )
Array ( [0] => 19 [MarketID] => 19 )
Array ( [0] => 20 [MarketID] => 20 )
Array ( [0] => 16 [MarketID] => 16 )
Array ( [0] => 17 [MarketID] => 17 )
Array ( [0] => 21 [MarketID] => 21 )
Array ( [0] => 5 [MarketID] => 5 )
Array ( [0] => 6 [MarketID] => 6 )
Array ( [0] => 22 [MarketID] => 22 )
Array ( [0] => 3 [MarketID] => 3 )
Array ( [0] => 23 [MarketID] => 23 )
Array ( [0] => 24 [MarketID] => 24 )
Array ( [0] => 4 [MarketID] => 4 )

"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#2 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 05 October 2006 - 03:58 PM

when you use print_r, u should use HTML <pre> tags encapsulating it so the output is formatted nicely.  regardless, your question is incredibly vague but anyways, $subscription is an array of returned results for whatever mysql query you're running and all of the MarketIDs are what's being returned as an answer to your query.

#3 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 05 October 2006 - 04:09 PM

My apologises for being vague...

When I see the below

Array ( [0] => 0 [MarketID] => 0 ) Array ( [0] => 14 [MarketID] => 14 ) Array ( [0] => 9 [MarketID] => 9 ) Array ( [0] => 18 [MarketID] => 18 ) Array ( [0] => 1 [MarketID] => 1 ) Array ( [0] => 19 [MarketID] => 19 ) Array ( [0] => 20 [MarketID] => 20 ) Array ( [0] => 16 [MarketID] => 16 ) Array ( [0] => 17 [MarketID] => 17 ) Array ( [0] => 21 [MarketID] => 21 ) Array ( [0] => 5 [MarketID] => 5 ) Array ( [0] => 6 [MarketID] => 6 ) Array ( [0] => 22 [MarketID] => 22 ) Array ( [0] => 3 [MarketID] => 3 ) Array ( [0] => 23 [MarketID] => 23 ) Array ( [0] => 24 [MarketID] => 24 ) Array ( [0] => 4 [MarketID] => 4 )

It looks to me that Array position zero holds marketID zero, but then it always continues with array position zero holding something different.

What I was expecting from my querry of "SELECT MarketID FROM Customer_Market WHERE CustomerID = '$client_select'" was a result that would look like

Array[0] =>0
Array[1] =>14
Array[2] =>9

etc etc
"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#4 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 05 October 2006 - 04:12 PM

It means you need to access the data in the array with a different syntax than:

echo Array[0];
echo Array[1];

etc.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#5 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 05 October 2006 - 04:15 PM

I don't need to know how to access the data, I need to understand what type of array I am being returned and why as it is not what was expected
"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#6 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 05 October 2006 - 04:38 PM

http://php.mirrors.i...fetch-array.php
Returns: An array that corresponds to the fetched row, or FALSE if there are no more rows.

Your SQL query looks something like "SELECT MarketID FROM ...";
When you run your query, $res3 holds the return set.
The while loop in conjunction with mssql_fetch_array() returns each individual record as an array.  Each array returned in this fashion has numeric indexes that correlate to each column in the SQL query in addition to associative indexes named after the columns themselves.

So...
<?php
$q = mssql_query($sql);
if($q){
  while($row = mssql_fetch_array($q)){
    echo $row[0] . "<br/>";
    echo $row['MarketID'] . "<br/>"; // prints same as above
  }
}
?>

PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#7 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 05 October 2006 - 04:59 PM

ok, how would I grab my output so that it is returned in the format

Array[0] =>0
Array[1] =>14
Array[2] =>9

or BETTER yet, if possible as

Array[0] =>1
Array[14] =>1
Array[9] => 1

Basicly an array would be crated and the indexex that match the marketid found would be set as 1 or true.
the maximum number of markets right now is 26

"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#8 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 05 October 2006 - 05:04 PM

for your better yet solution, you would need more information.  how are you specifying whether a market is 1/true or 0/false i'm guessing?  if you have this information in your db... the answer is simple.  create the sql statement to pull both sets of information and then from the results, format the outputting array as needed.  i.e.  =


while ($result = msyql_fetch_array($new_sql_statement)) {
  $tempArray[$result['marketID']] = $result['market_status'];
}

echo "<pre>";
print_r($tempArray);
echo "</pre>";


#9 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 05 October 2006 - 05:04 PM

This is under the assumption that your query is returning only valid market IDs and not just all of them.

<?php
// method 1
$q = mssql_query($sql);
if($q){
  $Ret = Array()
  while($row = mssql_fetch_array($q)){
    $Ret[] = $row['MarketID'];
  }
}

// BETTER yet method
$q = mssql_query($sql);
if($q){
  $Ret = Array()
  while($row = mssql_fetch_array($q)){
    $Ret[$row['MarketID']] = true;
  }
}
?>

PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#10 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 05 October 2006 - 06:21 PM

Well the table looks like this

CustomerID | Market ID
1                      0
1                      14
1                      9
1                    18

0 is a valid market, so there is a row for each market the customer is entitled to.

I have no input into how this db is organized, I just work with it.

Ultimitly I want to populate a form (check boxes) with the current access already selected and is why having everything in the array would be nice...

So I can say  for Market 14 <input type= checkbox if (array[14]) { echo value=1 } >
"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#11 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 05 October 2006 - 06:36 PM

Thanx a ton everyone, I think I'm good now  ;D
"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users