mATOK Posted October 5, 2006 Share Posted October 5, 2006 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/ Share on other sites More sharing options...
thepip3r Posted October 5, 2006 Share Posted October 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104289 Share on other sites More sharing options...
mATOK Posted October 5, 2006 Author Share Posted October 5, 2006 My apologises for being vague...When I see the belowArray ( [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 likeArray[0] =>0Array[1] =>14Array[2] =>9etc etc Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104309 Share on other sites More sharing options...
roopurt18 Posted October 5, 2006 Share Posted October 5, 2006 It means you need to access the data in the array with a different syntax than:echo Array[0];echo Array[1];etc. Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104317 Share on other sites More sharing options...
mATOK Posted October 5, 2006 Author Share Posted October 5, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104325 Share on other sites More sharing options...
roopurt18 Posted October 5, 2006 Share Posted October 5, 2006 http://php.mirrors.ilisys.com.au/manual/en/function.mssql-fetch-array.phpReturns: 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] Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104346 Share on other sites More sharing options...
mATOK Posted October 5, 2006 Author Share Posted October 5, 2006 ok, how would I grab my output so that it is returned in the formatArray[0] =>0Array[1] =>14Array[2] =>9or BETTER yet, if possible asArray[0] =>1Array[14] =>1Array[9] => 1Basicly 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 Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104364 Share on other sites More sharing options...
thepip3r Posted October 5, 2006 Share Posted October 5, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104369 Share on other sites More sharing options...
roopurt18 Posted October 5, 2006 Share Posted October 5, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104370 Share on other sites More sharing options...
mATOK Posted October 5, 2006 Author Share Posted October 5, 2006 Well the table looks like thisCustomerID | Market ID 1 01 141 91 180 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 } > Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104436 Share on other sites More sharing options...
mATOK Posted October 5, 2006 Author Share Posted October 5, 2006 Thanx a ton everyone, I think I'm good now ;D Quote Link to comment https://forums.phpfreaks.com/topic/23080-please-explain/#findComment-104449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.