Jump to content

Array problem


dodgeitorelse

Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.