dodgeitorelse Posted July 27, 2011 Share Posted July 27, 2011 my database has 2 columns which are clan and site. I have put both into arrays as such: while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $clanname[]= $row['clan']; $siteaddy[]= $row['site']; } I then look through $clanname array to see if I have a match and if I do I want to output the $siteaddy result. I tried this $found2 = array_keys($clanname, $server['o']['comment']); if(is_array($found2) && !empty($found2)){ foreach($found2 as $key3){ if($server['o']['comment'] == $clanname[$key3]) { $server2 = $siteaddy; } } } but all it returns is ARRAY and not the actual data for the $siteaddy. I would appreciate any suggestions. Link to comment https://forums.phpfreaks.com/topic/242991-array-problem/ Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 how are you outputting your array? Link to comment https://forums.phpfreaks.com/topic/242991-array-problem/#findComment-1248051 Share on other sites More sharing options...
xyph Posted July 27, 2011 Share Posted July 27, 2011 So I'm guessing $server['o']['comment'] will store a name of the clan that might be in the $clanname array? You could do something like this <?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $clan_data[]= array( $row['clan'], $row['site'] ); } // ... foreach( $clan_data as $clan ) { if( $server['o']['comment'] == $clan[0] ) { $server2 = $clan[1]; } } ?> Or if $server['o']['comment'] is defined before you loop your SQL results, you could also just do while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ if( $server['o']['comment'] == $row['clan'] ) { $server2 = $row['site']; } } Link to comment https://forums.phpfreaks.com/topic/242991-array-problem/#findComment-1248055 Share on other sites More sharing options...
dodgeitorelse Posted July 27, 2011 Author Share Posted July 27, 2011 I should have more clear.... my database has 2 columns which are clan and site. I have put both into arrays as such in a file called web_sites.php: while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $clanname[]= $row['clan']; $siteaddy[]= $row['site']; } then in another file called zone.php I have included web_sites.php I then look through $clanname array to see if I have a match and if I do I want to output the $siteaddy result. I tried this $found2 = array_keys($clanname, $server['o']['comment']); if(is_array($found2) && !empty($found2)){ foreach($found2 as $key3){ if($server['o']['comment'] == $clanname[$key3]) { $server2 = $siteaddy; } } } $output .= " <td style='padding-top:5px; padding-bottom:5px; vertical-align:top; text-align:center'> <table style='width:{$zone_width}; margin:auto; text-align:center' cellpadding='0' cellspacing='2'> <tr> <td title='{$server['s']['name']}' style='padding:0px; text-align:center'> <div style='left:0px; right:0px; top:0px; bottom:0px; width:{$zone_width}; white-space:nowrap; overflow:hidden; text-align:center'> $server2 </div> </td> </tr> The $server['o']['comment'] does store a name of the clan that might be in the $clanname array which is in a 3rd file called class.php which is included in the zone.php file. So basically if $server['o']['comment'] is someclanname and is found in the $clanname array I want the web site address that is stored in the $siteaddy array to display in the table. I hope this is clearer picture of what I have. Link to comment https://forums.phpfreaks.com/topic/242991-array-problem/#findComment-1248156 Share on other sites More sharing options...
xyph Posted July 27, 2011 Share Posted July 27, 2011 My first example will help you. Link to comment https://forums.phpfreaks.com/topic/242991-array-problem/#findComment-1248168 Share on other sites More sharing options...
dodgeitorelse Posted July 28, 2011 Author Share Posted July 28, 2011 Thank you Link to comment https://forums.phpfreaks.com/topic/242991-array-problem/#findComment-1248264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.