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.





Store The Entire Table In A Two Dimensional Array


I am reading info from a tab-delimited text file and I was wondering if anyone knew how to get this concept to work. I am trying to store the entire table in a two dimensional array, but the way I'm doing it right now won't work.

for($i=0; $i<$numrows; $i++)
{$columnsvalue[i] = explode(" ",$newfile[i]);}

does anyone else know how to better work with multi-dimensional arrays?




View Complete Forum Thread with Replies

Related Forum Messages:
Take The Entire Array And Apply The Htmlentities Function To Each Array Element
what I want to do is take the entire array and apply the htmlentities function to each array element. So here is what I am doing:

$result = $dbconn->query("select * from tablename");

while($case = fetch_array_html($result))

Here is the function:

function fetch_array_html($result)
{
$arr = mysql_fetch_array($result);
foreach($arr as $key=>$val)
{
$arr[$key] = htmlentities($val);
}
return $arr;
}

Here is the error I get: Warning: Invalid argument supplied for foreach() on line 129
What exactly am I doing wrong here? I can usually fix my own errors, but this one is dominating me.

View Replies !
Output Entire Table
I'm trying to output an entire table and then echo it. This sounded simple enough in my head but when I tried to do it I got stuck. What is the simplest way to output all the data in a table.

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 !
Display Entire Table And Edit
Is it possible with php to write a page to display and entire table into text boxes that will allow the user to edit the values in the text boxes and then click a single button to overwrite any changes? Currently I have the users using a formatted excel spreadsheet to modify the table entries but I would like to php it. I was going to use something like this, but I would prefer to be able to edit the table inline with the display rather than having the user have to select the line entry and edit it in a second page.

View Replies !
How To Edit An Entire Table Using A Form?
Currently I am able to create forms to update a mysql table. I can display information from my tables no problem.

I have since been trying to figure out a way I can edit mysql entries for a table on one page. Say I have a table with the headers

'id' 'header' 'url' 'content'

in a table called 'news'

How can I display all the rows from this table in a form that can be edited and re-submited.

I would also like to be able to delete entries by ticking a check box next to that entry. So I could in one go select 2 or 3 for deletion and update others and have it all update the database with one submit button at the bottom of the page. Code:

View Replies !
Adding An Entire Column In A MYSQL Table
I run a site where members submit photos and get points based on the photos they submit. I'd like to get their total points, but I'm at a loss on how to do that.

I have a mysql table set up with every photo that includes title, description, the user who submitted it, and the number of points that picture is worth.

I'd like to write a query that goes through that table, and whenever the 'user' column matched the user, it added up the points in that row. It sounds easy, but for the love of me, I can't figure out the mysql commands to make it work. Any help at all would be awesome.

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 !
League Table - Multi-dimensional Arrays
I am seting up a league table for a friend and i have found i need to use multi-dimensional arrays. I have little experience of these in PHP and this is what's wrong in my code i believe.

Writing to this array seems to be the problem as there should be more than one result per team yet it only displays one. It should be passing through once, storing all the data in this array and then outputting it after however the scores that should be in the array aren't except for the last one. PHP Code:

View Replies !
How To Copy An Entire Array?
can I do this? You see, I want to pass my values in to another page, but you can imagine how it would be insane to try and copy each value in the array individually

<A HREF="thepage.php?array[0]=$array[0]&array[1]=$array[1]... etc

is there a way to compress an array into a single variable, and then decompress it

like:
Code: $compressedArray = compress(0, 10, $array);
where 0 is the start index, and 10 is the end index

then when I want to use it on the other page
Code: for ($x=0; $x<=10; $x++){
$newArray[$x] = decompressMe($x, $compressedArray);
}
I'm sure that there must be some simple little thing like that.... I looked at the php manual, but couldn't really see anything like I'm talking about (or maybe I dont understand it )

View Replies !
Passing An Entire Array In PHP
I saw a previous post about sending arrays but did not quite
understand the answers.

The problem is that I would like to pass an entire array as a hidden
input field from one php script to another. I've simplified the code
where form1.php calls form2.php when "Go" is hit:

form1.php
=========

<html>
<head>
<title>Form 1</title>
</head>
<body>
<h1>Form 1</h1>
<form action="form2.php" method=post>
<?
$record[0]="One";
$record[1]="Two";
printf("<input type=hidden name="record[]" value="%s">",$record);
?>
<input type=submit value="Go">
</form>
</body>
</html>

form2.php
=========
<html>
<head>
<title>Form 2</title>
</head>
<body>
<h1>Form 2</h1>
<?
$record=$_POST['record'];
printf("$record[0]=%s",$record[0]);
printf("$record[1]=%s",$record[1]);
?>
</body>
</html>

The result is:
Form 2
Array=Array=

How do I fix this?

View Replies !
Plugging In The Entire Array Into The SET Part
The code is making an array for one value and then plugging in the entire array into the SET part when it should only be one value. Here is the code, first part is the html form. PHP Code:

View Replies !
Pass The Entire Array Through A Form.
Im working with an array in my php script and need to pass the entire array through a form. Here is the script. Take a look and tell me if you can see my mistake.

I create a dynamic entry screen that has multiple values that I would like to update and want to place them all into an array to update them. At the mo no values are being posted at all. Code:

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 !

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