Jump to content

Multi Dimensional Array:


cr-ispinternet

Recommended Posts

Hi there,

 

Im realy really crap with arrays and would like some help finally mastering it... if possible

im trying to use a graph system which requires multi dimensional arrays and im looking for the following

 

        include('includes/connection.php');
        $base_url = "http://domain.co.uk";

        // Mysql query to gain actual variables
        $query = "SELECT * from email_delayed_campaigns where processed='Y' ORDER BY id DESC LIMIT 2";
        $result = mysql_db_query('database',$query);
        while($row = mysql_fetch_object($result)) {

        $Array['one']['campaign_name'] = $row->campaign_name;
        $Array['two']['campaign_name'] = $row->campaign_name;

        }

        echo $Array['one']['campaign_name'];
        echo $Array['two']['campaign_name'];

 

in essence the above i want or should have 2 campaign names but currently

i have 2 rows but the same campaign name, can any oen tell me what im doing

wrong or a way to make it easier for me to learn these...

 

this is the code line im trying to inject with the array parts

 

$chart[ 'chart_data' ] = array ( array ( "", "$campaign_name", "$campaign_name" ), array ( "Attending", 20 ), array ( "Not Attending", 10) );

 

its a graph system, so the above would show 2 campaign names ( the latest 2 )

just not sure how i can sort them in to an array so i could call the following...

 

$chart[ 'chart_data' ] = array ( array ( "", "$array['name']['campaign_name_one']", "$array['name']['campaign_name_two']" ), array ( "Attending", 20 ), array ( "Not Attending", 10) );

 

thats my thinking, i may be totaly wrong

 

Thanks for any replies

 

Alan

Link to comment
https://forums.phpfreaks.com/topic/111550-multi-dimensional-array/
Share on other sites

HI there,

 

call me stupid, but ive tried your suggestion and i get a white page error

not sure how ure example will give me my array either??

 

like i said im really bad with arrays

just want to be able to get the following

 

so i can just

 

echo $campaign_name 1 and campaign_name 2 but in array format

if that makes any sense..

 

Alan

 

thanks for your reply

 

 

Barand,

 

thanks for your patience, i did get it working in the end and is relatively easy

to get working once you understand it. Managed ot get my array perfect now.

But would like some advice on an additional problem...

 

I have am array with populates a graph, but every time i try and populate this

array for a varible instead it doesnt lie it and bombs straight away.

 

heres the array

 

$chart[ 'chart_data' ] = array ( array ( "", "2005", "2006"     ),
                                 array ( "region A", -20, 45    ),
                                 array ( "region B", -40, 65  ) );

 

what id liek ot try and do is populate those static entries with variable from my

array which ive just recently created... wonder if tyat makes sense to you???

 

Alan

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.