Jump to content

Archived

This topic is now archived and is closed to further replies.

mATOK

please explain

Recommended Posts

what this means? I get it as output from

[code]
while ($subscription = mssql_fetch_array($res3)) {
                                                print_r($subscription);
                                        }
[/code]

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 )

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
It means you need to access the data in the array with a different syntax than:

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

etc.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
http://php.mirrors.ilisys.com.au/manual/en/function.mssql-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 [b]each individual record[/b] 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...
[code]
<?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
  }
}
?>[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.  =

[code]

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

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

Share this post


Link to post
Share on other sites
This is under the assumption that your query is returning only valid market IDs and not just all of them.

[code]<?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;
 }
}
?>[/code]

Share this post


Link to post
Share on other sites
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 } >

Share this post


Link to post
Share on other sites
Thanx a ton everyone, I think I'm good now  ;D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.