Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Making Three Linked Tables Into A 3 Dimensional Array


I want to make the result of 3 tables linked through foreign keys into a 3-dimensional array that reflects their relationship without repetition and without having to call the database more three times.

I know I'm doing a couple of things wrong, one thing for instance is initializing a variable at the end of the loop to remember the previous value s that it does not repeat itself, surely there must be a more elegant way to go about this, but I'm lost and I've been stuck on this all day. Code:




View Complete Forum Thread with Replies

Related Forum Messages:
Making Mysql Result Into Multi-dimensional Array
My php problem is I want to make the result of 3 tables linked through foreign keys into a 3-dimensional array that reflects their relationship without repetition and without having to call the database more three times.

I know I'm doing a couple of things wrong, one thing for instance is initializing a variable at the end of the loop to remember the previous value s that it does not repeat itself, surely there must be a more elegant way to go about this, but I'm lost and I've been stuck on this all day. Code:

View Replies !
Making A Linked List
I'm trying to create a heirarchical linked list of sorts, and I'm
looking for advice as to how best to set up the arrays. In other
languages, I might use a pointer array to other pointer arrays, but in
PHP, I'm a bit stumped.

What I have is a list of simple, small arrays. I'd like to figure out
the appropriate data structure so that each element knows which
element is it's "parent," and so that each element can have multiple
children. The best way to think of this is like an outline wherein
each fork has a variable number of elements.

The tricky part is that given a specific element, I'd like to be able
to easily list its children's IDs.

I'm storing the individual elements in a MySQL database. So for each
element, I have a field with the data (just text) and a field telling
the unique ID number of the element; and then I suppose I can have an
additional field containing the ID of the parent.

My best guess so far as to how to do this is to read all of the
elements from the database. As they come in one by one, I create an
array for each one to conain a list of its children. When a specific
element comes in, we ask for its parent ID and then add its ID to the
parent's array-of-children.

View Replies !
Linked MySQL Tables
I am putting together a Help Desk Automated System. I need to sore different sets of relative data to a user but retrievable based on there Session ID (there account number) (e.g. user info, user posts, user contacts, etc). So I am guessing I need 'linked' tables in mySQL. Not sure how to do that.

I already have one table set up with login info, and user authentication, carrying the Session ID throughout each section. Instead of re-doing any work done (many hours) I would just like to add smaller tables from time to time, easily, but all accessed bu the 'user' based on there Session ID.

View Replies !
Creating Two Linked Tables
Is this right, Im trying to create 2 tables (ACTIVITY, COMPANY) so that only 1 company is linked to an activity. CREATE TABLE COMPANY

(
C_ID INT NOT NULL AUTO_INCREMENT,
C_NAME VARCHAR(20),
C_CITY VARCHAR(20),
C_STATE VARCHAR(10),
C_DESC TEXT,
RATIONALE TEXT,
contact_NAME VARCHAR(20),
contact_PHONE VARCHAR(15),
contact_EMAIL VARCHAR(20),
MEDIVAS VARCHAR(20),
PRIMARY KEY (C_ID)
);

CREATE TABLE ACTIVITY

View Replies !
Print Results From Two Tables Linked Together
I need to be able to pull data from a table (product_status, which has many other fields) and cross reference it with data in another table (warranty). The data in product_status lies in a field called warranty_number, and is simply an id number (1,2,36,etc.) The data in table warranty, field warranty_comment,

is text (30 day warranty, one year warranty, etc.). The warranty table also has a field called warranty_id, which corresponds to each text entry in the table. This number matches the number in table product_status, field warranty_number. So I need to be able to print results of product status, but instead of printing simply the number in field warranty_number,

it needs to check table warranty, field warranty_id, then match the number, then pull the text from warranty_comment and print along with all the other results from product_status. I have some code that works, but it is not at all designed for this, so I won't post. Is this enough info to explain what I need? I have tried searching, but found nothing that I could see that would help.

View Replies !
Primary Keys And Linked Tables
To populate my Members table let's say I have FormX that has the follwing Input fields -Name, Age and Country.

The Country is a Menu Field and the values get populated from another table, which have two colums, Country_ID and Country.

Which would be right thing to do? Populate Memers table with the Country_ID or Country? Is a Unique/Foriegn Key required when the Countries itself would be not be repeated and unique?

View Replies !
MySQL Inserting Into Multiple Tables Linked Records
Using MySQL can anyone tell me how to most efficiently insert a collumn
in 'table1' retrieve the id from this record and insert mutliple
records into 'table2' with a collumn for the id in 'table1' which links
the two recordsets

View Replies !
Assigning A Multi-dimensional Array To & From A Session Variable Loses The Array
I have created a multidimensional array and then assigned that array to a session variable so that I can use it easily on another page.  However, when I go to the array later, there's never anything in it. Code:

View Replies !
Making Tables.
So I have this function to turn an object into a table row. I have put this in two different objects. But the problem is one works and one does not, despite being almost exactly identical. Code:

View Replies !
Making A Tables
I'm working on a script that will display some tables side by side in a larger table. I want to make it so that they can align with each other no matter how many tables there are (the number of tables is set by the user).

View Replies !
Finding Elements Of An Array In Another Multi-dimensional Array
So I have 2 arrays:
one contains userids. It may look like:
user_id[0] =12,
user_id[1] =30,
user_id[2] =43

The other is a multi-dimensional array with fields like:
user_info [0] = Array
(
[user_id] =13
[user_flag] =1
[url] =http://www.example.com?index,0
)
user_info[1] =Array
{
Array
(
[user_id] =120
[user_flag] =1
[address] =1234 Main St, Anytown, USA
[url] =http://www.yahoo.com
)
user_info[2] =Array
{
Array
(
[user_id] =130
[user_flag] =1
[address] =134 Main St, Anytown, USA
[url] =http://www.google.com
)

View Replies !
Array Sorting Blues....2 Dimensional Array
I have a 2 dimensional array where one col contains a Unix style date and the other contains a filename. I read through a directory to get this info. I can load the array and print it out just fine, but I can't seem to sort it using any of the sort functions! I want to reverse sort them, since they are news stories that I want to display in the correct order by date. When I try to sort I get a "Warning: Cannot compare arrays or objects" message. I have the feeling it's something stupid on my part but can't find any good examples anywhere.

Anyone have an idea about this?

P.S. I know a database would solve this but sadly it's not an option for me right now...

View Replies !
Turn Array Into Multi-dimensional Array?
How can I take an existing array and turn it into a multi-dimensional array? I want to get a single row out of a MySQL table and have it in an array, but have along side the values the true field (column) length for each of the fields from the table. Here's my stab at it:

$userDetails = mysql_fetch_array($resultID);
$i = 0;
while ($i < mysql_num_fields($resultID))
{
    $userDetails[$i][2] = mysql_field_len($resultID, $i);
    $i++;
}

And I guess the follow up question (if this is indeed possible) is will this work with a multi-row return from the DB also?

View Replies !
3 Dimensional Array
I have been summing one element of a 3 dimensional array. My method works, but I think there is a better way to do it. My current way of doing this is causing me problems later in my code.

line 1 for ($j = 0 ; $j < $z ; $j++){
line 2 for ($k = 0 ; $k <= $y; $k++){
line 3 for ($i = 0 ; $i < $x; $i++){
line 4 $foo[$j][$k] = $bar[$j][$k][$i] + $foo[$j][$k];};};}

View Replies !
Count 2 Dimensional Array
i need to count 2-dimensional array $this->myarray[$a][$b] after $a, my code PHP Code:

View Replies !
PHP 4 OO Issue - 3 Dimensional Array
Hello, I have this simple script that i have a 3 dimensional array. However I am kinda new to OO php, and it keep getting the same error? Any ideas?

class maps{

//Initalize the city array
var $City = array();
$City['city1']['Dundas']['Codes'] = "L9H, L85"; //ERROR LINE
$City['city1']['Dundas']['Amount'] = 13915;
$City['city2']['North Burlington']['Codes'] = "L7M, L7P";
$City['city2']['North Burlington']['Amount'] = 19668;
$City['city3']['South Oakville']['Codes'] = "L6K, L6L, L6M";
$City['city3']['South Oakville']['Amount'] = 26044;

function display_cities(){
echo "hi";
foreach($this->City as $kCity=>$vCity){
echo $kCity." = ".$vCity."<br>";
}
echo "bye";
}
}

Error is in this class file on the line noted.
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION

This is probably really simple, but i've been looking at it for a couple hours and cant figure it out.

View Replies !
Two Dimensional Array Problem
I want to put the contents of a csv file into a 2 dimensional array so that
I can access any element in a $table[x][y] manner and have come up with the
following code:

$complete = file("source.csv");
$row=0;
foreach ($complete as $value) {
$data = explode(",", $value);
$table[$row] = $data;
$row++;
}
echo "$table[6][4]";

However the echo statement returns "Array[4]" instead of the 4th element in
the 6th row.

Any suggestions on what I ought to be doing please to make $table a proper 2
dimensional array?

View Replies !
How Do I Sort My Two Dimensional Array?
How do I sort my two dimensional array? I want to sort "numb" numerically, then "part" alphabetically. Code:

View Replies !
Getting Data Out Of Three Dimensional Array
I want to extract data from 3-dimensional array into one dimensional array here's example of two arrays that i add into one: PHP Code:

View Replies !
Turn Xml Into 2 Dimensional Array
Well, www.php.net seems utterly crashed. Does anyone know how to get
an XML stream and turn it into a 2 dimensional array?

View Replies !
Sorting A Two Dimensional Array
I have an array, thus:

Array (
[0] => Array ( [Freq] => 28 [Name] => Tomato )
[1] => Array ( [Freq] => 4 [Name] => Banana )
[2] => Array ( [Freq] => 54 [Name] => Orange )
[3] => Array ( [Freq] => 24 [Name] => Eggplant )
[4] => Array ( [Freq] => 5 [Name] => Courgette )
[5] => Array ( [Freq] => 4 [Name] => Apple )
)

I would like to be able to sort it either by the Frequency or the Name
of the fruit or vegetable.

I just can't seem to get it to work. I'm sorry - I realise that this is
probably really easy but my brain isn't working today and the examples
on php.net seem incomprehensible to me.

View Replies !
Returning A 2 Dimensional Array
I am trying to program a function to return a 2 dimensional array, but
it's not working. I reduced the return value to 1 dimension and
tested that to make sure that the problem wasn't elsewhere. It had no
problem when the array was 1 dimensional.

Is there something different I need to do in order to return a 2
dimensional array from a function?

View Replies !
2 Dimensional Array And Foreach
I have a 2-dimensional array.  so I run it through two foreach loops to get the data out.  but, i want the foreaches to run in reverse.  lets say I have an array[3,2].  right now my foreach prints [1,1] [1,2] new line [2,1][2,2] new line [3,1][3,2] and i want it to print [1,1][2,1][3,1] new line [1,2][2,2][3,2]

View Replies !
Sorting Two Dimensional Array
I have a two dimensional array that I need to sort based on a total of values in the second dimension. The top level array has a part number and another array as its elements. The second array consists of defect types and defect quantity corresponding to the part number. I am able to sort the second defect array by defect type (so whichever type has the highest quantity shows up first) but I am not sure how to sort so that the parts with the highest total defects are first. Essentially I need to sort based on the total quantities in the second array, but I am not sure how to do that on the fly. Here is a print_r of the array.

Part#101 Array ( [Scratches] => 6 )
Part#102 Array ( [Scratches] => 174 [Handling] => 22 [Supplier Mold Defect] => 9 [Dirt] => 9 )
Part#103 Array ( [Scratches] => 167 [Dirt] => 116 [Handling] => 4 [Water Spots] => 3 [Supplier Mold Defect] => 1 )
Part#104 Array ( [Scratches] => 20 [Supplier Mold Defect] => 4 )

After sorting the part order should be:
Part#103 (291 total defects)
Part#102 (214 total defects)
Part#104 (24 total defects)
Part#101 (6 total defects)

View Replies !
Does Php Have A Multi Dimensional Array?
Does php have a multi dimensional array?

So eg. $someData[i][j]

View Replies !
Access A One-dimensional Array
if i have an array such as:

$_testArray['one'] = array();
$_testArray['one']['subone'] = somethingone;
$_testArray['one']['subtwo'] = somethingtwo;

and then i want to access these values elsewhere. how would i go about acessing the subone and subtwo items. does this make sense? i was able to access a one-dimensional array by using something like:

$_testArray['one'] = array();
$_testArray['one'] = somevalue;
$_testArray['two'] = somevalue2;

and then access it using:

$variable = "one";
so i guess i don't know how to do this for ['one']['subone']

View Replies !
Syntax For Two Dimensional Array
I have got some problems using a two dimensional array in an if expression:

PHP does not like:

if (table[$j]["banana"]==0)

and says:

Parse error: parse error, unexpected '[' in script.php on line 203

"if ({table[$j]["banana"]==0})" was also not accepted, can anyone help `?

I would also use the value in a two dimensional array as an index for another array:
$array[{table[$j]["banana"]}]

PHP does not like this, too.

View Replies !
Multi-dimensional Array
I have a function that loops through email addresses and checking them to see if they are valid. if the email address is valid i want to add it to the $validEmails array, and if its invalid i want to add it to the $invalidEmails array. BUT, in order to return this data from a function it will need to be a multi-dimensional array.

View Replies !
Subtotals In 2 Dimensional Array
Using array_push() from a collection of tables I have created the array below for a report.

2007-08-21, Interest, Dad, 82.00
2007-09-01, Electricity, Mum, 63.14
2007-08-20, Petrol, Dad, 18.71
2007-09-01, Electricity, Mum, 85.00
2007-08-19, Interest, Dad, 83.00

In the report I want to produce summaries like:

Electricity = 148.00
Interest = 165.00
Petrol = 18.71

And:

Dad = 188.00
Mum = 148.00

The categories like Electricity, Interest, Dad etc will be different depending what the user has entered. Producing the the basic report is straight forward. Producing the summaries has left me brain dead. I could have obtained the totals from the database but for ease (I thought) and to teach myself how to use multidimensional arrays I tried this approach. Can it be done?

View Replies !
Multi Dimensional Array
Here is my array. PHP Code:

$playerarray = Array ( [0] => Array ( [Player1] => jimmydee2 [Reg] => 1 [Rank] => 3 [Rating] => 1490 [Checkedin] => Checked In [Wins] => 0 [Losses] => 0 ) [1] => Array ( [Player1] => bob2 [Reg] => 2 [Rank] => 1 [Rating] => 1738 [Checkedin] => Checked In [Wins] => 0 [Losses] => 0 ) )

View Replies !
How Do You Sort A 2-dimensional Array?
$fbArray[$j] = array($feedbackCategoryArray[$i]['attributes']['NAME'] =>
$feedbackCategoryArray[$i]['attributes']['DISPLAYNAME']);

I can't begin to fathom in my befuddled mind how to sort this array $fbArray
into alphabetical order according to
$feedbackCategoryArray[$i]['attributes']['NAME'] - I am utterly lost, can
someone explain in detail how I would do it and why.

View Replies !
"Array To String Conversion" Error When Constructing A Multi-dimensional Array
I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.

Code below:

$_SESSION["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);

It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

View Replies !
Sorting Multi-dimensional Array
Sorting multi-dimensional array

I have this array:

Array
(
[0] => Array
(
[account] => 263
[counter] => 1
)

[1] => Array
(
[account] => 324
[counter] => 5
)

[2] => Array
(
[account] => 972
[counter] => 3
)

[3] => Array
(
[account] => 1316
[counter] => 3
)

[4] => Array
(
[account] => 1380
[counter] => 1
)

[5] => Array
(
[account] => 1880
[counter] => 2
)
)

I need to sort by the key [counter], how can I do that?

View Replies !
Multi-dimensional Array For Checkbox
Can there be a multi-dimensional array for checkboxes?

View Replies !
How Can I Sort A Multi-dimensional Array?
How can I sort a multi-dimensional array?

For instance:
a[Name], a[adress], a[number of messages].

How to sort on the item of number of messages?

View Replies !
Two-Dimensional Array Insertion And Print
1. return results from an Oracle query into an array. there are 3 fields and approx. 2,000 records.

2. insert the results into an array of some type, inside of a loop, obviously.

3. print the results so i can verify the query is working.

PHP Code:

View Replies !
Multi-Dimensional Array Question
Can you have a multi-dimensional array like this?

$Test[0]['Fname'] = "John";
$Test[0]['Lname'] = "Doe";

Or do you have to use only numbers?

View Replies !
Building Multi Dimensional Array
I am trying to build a multi dimensional array from an unsorted array. I have an array made up of the lines in a text file, each line is a comma seperated set of fields. The first two fields are the lines id and it's parents id; eg Line ID, Parent ID, Data

1, 1 , one
2, 2, two
3, 3, three
4, 1, four
5, 4, five
6, 1, six
7, 2, seven

I am trying to build a multi dimensional array so that the final array would look like;

-- one
---- four
------ five
---- six
-- two
---- seven

View Replies !
Make A Multi-dimensional Array
I am trying to make a multi-dimensional array. I am having trouble adding to the array. What I mean by that is using the array_push() function. Does anyone know how to add to a multi-dimesional array?Ex.

$somearray = array("1" => array("This is one"));

#The line above works. how can I add

"2" = > array("This is two");

View Replies !
Sessions And A Multi-dimensional Array
I'm writing a shopping cart w/ Sessions and a multi-dimensional array. I am only storing product id and qty (for right now, but decided on the multi-dimensional array for expansion purposes - storing customer instructions, etc.) I have come up with two paths, but can't decide which is better.

1. storing info based on product id:
...[cart][$prod_id] = array("qty" => $qty)

This, of course would allow for easy product checks: if ([cart][$prod_id]) {...}, but unless I store the $prod_id in the prod_id array as well, I'd be forced to use foreach(array_expression as $key => $value) when displaying the cart (as I also want the product id displayed next to the product name)

2. storing info based on item number:
...[cart][] = array("id" => $prod_id, "qty" => $qty)

This makes for more code when checking if the product is already in the cart (multiple foreach statements), but should allow the cart to be displayed more easily and logical.

View Replies !
Counting The First Dimension Of Two Dimensional Array
I'm trying to count just the items in the first dimension of a two dimensional array.
It seems like: PHP Code:

View Replies !
How To Print Elemnets Of N-dimensional Array?
What is a common way to print elements of a multidimensional array? I
treid to do it in the straightforward way:
$input_list[0][0] = "Something";
print "$input_list[0][0]";
And it does not work.

The solution that I found is to use intermediate variable:
$array = $input_list[0];
print "$array[0]";
printArray( $output_list[0] );

Are there any more elegant (or just common) ways to do it?

View Replies !
Changing A Value Of An Element In A Two Dimensional Array
I am having a problem with array manipulation.

in my php script i am reading from a csv file.
the content of file is like this:

View Replies !
Convert Two-Dimensional Array To String
I'm trying to convert a two-dimensional array to a string that I can put in a database. It needs to be searchable so the serialize() function will not work. I found a script at php.net that will implode a multi-dimensional array and it works fine. The script is: Code:

View Replies !
Printing From A Multi-dimensional Array
I have to create a multidimensional array that data for a bank will be stored in then from that array I will print it. My boss said to first program it like i am recieving the array. Then later he will have me create the array.

Order multidimensional Array I will recieve will be arranged in and the printed like this. Code:

View Replies !
Multi-dimensional Array Sorting
I need some help sorting an array, same in structure as:

Array
(
    [assoc1] => Array
        (
            [key1] => value
            [key2] => value
            [key3] => value
        )

    [assoc2] => Array
        (
            [key1] => value
            [key2] => value
            [key3] => value
        ))

What I want to do is sort the array by the value in say the key2 "column". Depending on input, the value to sort by may be key3 or some other key. 

I've looked at array_multisort(), but I'm not sure how I can specify what exact column I want to sort by, without affecting the rest.

View Replies !
Sorting A Multi-Dimensional Array
I have an array that prints like this:

Array (
[dist] => Array (
[0] => 1.0
[1] => 0.2
[2] => 0.9
[3] => 1.0
)
[loc] => Array (
[0] => Dean Playground Park
[1] => Eckhart Park
[2] => Pulaski Park
[3] => Skinner Park
))

I would like to sort this array by DIST but have the keys match up, IE Code:

View Replies !
Create Multi Dimensional Array
$miles_zip = array();

foreach ($subzip as $key => $value) { //3

$miles = $z->get_distance( $zipCode, $key);

$miles_zip[$i] = $miles ;
$i++;
} //3

$count = count($miles_zip) ;

for ($i = 0; $i < $count; $i++)
echo " $miles_zip[$i]<br> ";

I am trying to put $key and $miles in a multi dimensional array. I have tried different ways, it is not working. All I see online is syntax of creating static multidimensional arrays. Can somebody guide me how can I create a dynamic one.

View Replies !
Multi Dimensional Array Sort
I am trying to sort a multi dimensional array. I need all elements of the first dimension sorted in descending order based on the fourth element of the second dimension. The elements are not named(only 0-X), but what i need is array[x][4] to be sorted.

View Replies !
Sort Multi-dimensional Array
does anyone know how i can sort a multi-dimensional array by a specific field ?

for example i want to sort arr[m][n] where n=2,

but i need the data of every array to follow that order. Code:

View Replies !
Sorting Multi Dimensional Array
I have a multi dimensional array which has gone out of whack and I need to sort it, but am having trouble. I have an array $dateOrders as such: Code:

View Replies !
Sort A Very Big Multi-dimensional Array
I'm trying to sort a very big multi-dimensional array, up to 10 dimensions and having a heck of a time getting it to work.

I've tried using usort , creating a compare function and strcmp, but it just ends up being an even bigger mess.

Maybe I am making it more complicated than it really is, or maybe it's just too complicated. Code:

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved