dagnasty Posted July 16, 2006 Share Posted July 16, 2006 [code]while($row = mysql_fetch_array($result)){ $search["{$row['searchquery']}"]++; $total["{$row['Count']}"]++;}[/code]How exactly does this structure the array?$search[0]; does not print anything, and neither does $search[0][0];But print_r($search); puts out a result such as this:Array ( [superman] => 1 [prey] => 1 [pirates] => 1 [stargate] => 1 [lost] => 1 [psp] => 1 [entourage] => 1 [superman returns] => 1 [cars] => 1 [Pirates Of The Caribbean] => 1 ) Can someone please explain how the above code sets up the array? I don't understand it at all.What should I do to print out a single item in either of the 2 arrays? Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/ Share on other sites More sharing options...
xyn Posted July 16, 2006 Share Posted July 16, 2006 [b]Edit:[/b]use this:[code=php:0]while($row = mysql_fetch_array($result)){ $search["{$row['searchquery']['prey']}"]++; $total["{$row['Count']['pirates']}"]++;}[/code] Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59022 Share on other sites More sharing options...
dagnasty Posted July 16, 2006 Author Share Posted July 16, 2006 $result = @mysql_query("SELECT DISTINCT searchquery, COUNT(*) AS `Count` FROM tscrapestats GROUP BY searchquery ORDER BY `Count` DESC LIMIT 10"); Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59023 Share on other sites More sharing options...
xyn Posted July 16, 2006 Share Posted July 16, 2006 check the update ^^ hope it helps define the problem. Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59024 Share on other sites More sharing options...
zq29 Posted July 16, 2006 Share Posted July 16, 2006 [quote]$search[0]; does not print anything, and neither does $search[0][0];[/quote]That is because you have no numerical keys for that array. $search['pirates'] holds the value "1". The "++" on the end of your variables (or array keys) is just incrementing it's value by one. Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59026 Share on other sites More sharing options...
dagnasty Posted July 16, 2006 Author Share Posted July 16, 2006 so other than print_r there's no way to print each individual item? I'm so completely lost with arrays...Can I use mysql_result to print the Count and the searchquery? Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59029 Share on other sites More sharing options...
Barand Posted July 16, 2006 Share Posted July 16, 2006 [code]<?php$result = @mysql_query("SELECT searchquery, COUNT(*) AS `Count` FROM tscrapestats GROUP BY searchquery ORDER BY `Count` DESC LIMIT 10");while($row = mysql_fetch_array($result)){ $search[$row['searchquery']]++; $total[$row['Count']]++;}?>[/code]As you are grouping by searchquery, DISTINCT is unnecessary. They will be anyway.The keys to the $search array are 'superman', 'lost' etc.eg. These will always be 1 as each occurs once in the results [code]echo $search['superman'];[/code]The keys to the $total array are the count values from the queryeg how many had a count of 10?[code]echo $total[10];[/code] Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59030 Share on other sites More sharing options...
Barand Posted July 16, 2006 Share Posted July 16, 2006 try[code]<?php$result = @mysql_query("SELECT searchquery, COUNT(*) AS `Count` FROM tscrapestats GROUP BY searchquery ORDER BY `Count` DESC LIMIT 10");while(list($sq, $c) = mysql_fetch_row($result)){ echo "$sq : $c <br>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59031 Share on other sites More sharing options...
dagnasty Posted July 16, 2006 Author Share Posted July 16, 2006 That works great and is much easier to understand than what I was doing before.Thanks guys. Link to comment https://forums.phpfreaks.com/topic/14779-array-help-please/#findComment-59033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.