TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-30-2007, 07:18 PM   #1 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default 3 Dimensional Array

Hey guys,

I've been trying to figure out something for quite some time now. Decided to give it a try.

PHP Code:
    $result query('SELECT * FROM user_data WHERE user_id = "2"');
    
$b03tz mysql_fetch_array($result);

    
$result2 query('SELECT * FROM user_data WHERE user_id = "3"');
    
$respawn mysql_fetch_array($result2);
    
    
$globals = array();
    foreach (
$respawn as $key => $value) {
        
array_push($globals$respawn2[$key]);
    }
    foreach (
$b03tz as $key => $value) {
        
array_push($globals$b03tz[$key]);
    } 
In plain man terms, it's shows a list with some data.

What do I want to do?
We have 2 arrays in an array. The one exports ReSpawN's stats, and the other exports b03tz's. In $global, I've pushed $respawn row results and $b03tz row results.

Now the question is, how do I make them show up in a list like so:
echo $global[$respawn[1]]; or something like that. It's completely new to me so I haven't got a clue what to do.

I also want to GENERATE the difference. When my level of, lets say, a building, is higher than that of b03tz, it shows the difference. For example:

ReSpawN 1
b03tz 0
Difference 1
Mine of course, is green, and b03tz's is red.

Can one of you guys help me out here?

Mark
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 12-30-2007, 08:48 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Hi Mark,

I'm afraid I don't fully understand what you are trying to do, but I've taken a guess based on your thread title :D

At the moment, your current code would make your $globals array look something like this:

PHP Code:
/*
Array
(
    [0] => respawn_value1
    [1] => respawn_value2
    [2] => respawn_value3
    [3] => b03tz_value1
    [4] => b03tz_value2
    [5] => b03tz_value3
)
*/ 
Which I'm guessing is not what you where after. I've made some adjustments to the code to put your 2 arrays into a 3 dimensional array:

PHP Code:
$b03tz = array('b03tz1' => 'b03tz_value1',
               
'b03tz2' => 'b03tz_value2',
               
'b03tz3' => 'b03tz_value3');

$respawn = array('respawn1' => 'respawn_value1',
               
'respawn2' => 'respawn_value2',
               
'respawn3' => 'respawn_value3');    

           
$globals = array(); 

foreach (
$b03tz as $key => $value)
{
    
$globals['b03tz'][$key] = $value;
}

foreach (
$respawn as $key => $value)
{
    
$globals['respawn'][$key] = $value;

This new code makes your $globals array look like this:

PHP Code:
/*
Array
(
    [b03tz] => Array
        (
            [b03tz1] => b03tz_value1
            [b03tz2] => b03tz_value2
            [b03tz3] => b03tz_value3
        )

    [respawn] => Array
        (
            [respawn1] => respawn_value1
            [respawn2] => respawn_value2
            [respawn3] => respawn_value3
        )

)
*/ 
Is this the sort of array that you where trying to achieve?

To access the values in this array you would use something like:

PHP Code:
echo $globals['respawn']['respawn2'];

// This would echo "respawn_value2" if using the above arrays 
As for the comparison question, if you could give some examples of the data in the arrays I can probably knock some examples up for you.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-07-2008, 05:12 PM   #3 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Then again ^ thats just a two dimentional array. To be honest only reason I could see a 3 dimentional array being used is because you are doing something with levels and maps ie:

$game['level_1']['map1']['map_peice1'] = 1;
$game['level_1']['map1']['map_peice2'] = 1;

So maybe 3 dimentional arrays are not what he means possibly what you said is what hes looking for :).
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:31 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design