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




Adding New Values To An Array That Already Contains Values..


is it possible to append new values to an array that already has values in it??

say, i have my existing array;

existing array;
$array = array([66314] => 66314 , [66315] => 66315) ;

then , when i check my checkbox on my next page, the ids should be appended to the $array:

array that needs to be added to the $array;

$array = array([66316] => 66316,[66317] => 66317,[66318] => 66318);

how should it be done??




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Adding Values To An Array
i have an array that gets filled by users hitting a FAVORITE button on 'product' pages. I can get one value, but the value doesn't stay after the page has refreshed... so i think I need to use Sessions but I have tried before and have always been unsuccessful... here is the code that displays the favorite product. PHP Code:

Adding Values Onto An Associative Array...
I'm trying to develop a simple class which through the interface you can add elements to an array. The method I have used to add the elements is setContentFields($name, $field_type), I have used an array counter variable to increment the array index each time. To me this seems like a workaround, and I wondered if there was a more elegant way of doing this.

The class is as follows:

Adding Sums Of Array Values
I have two arrays:
('a'=>1,'b'=>3,'c'=>2,'d'=>6)
('a'=>2,'b'=>0,'c'=>4)

I need a very efficient function to add the values together for each element. For instance, the output would be an array:

('a'=>3,'b'=>3,'c'=>6,'d'=>6)

This function could potentially be used in billions of iterations, so it needs to be as efficient as possible.

Adding Values To A Superglobal Array
i have a variable (well, an Object) which is needed in beneath every Script.
it's not needed to be changed during the whole script, so i like to access
it easyli without passing by or declare it as global in every function.
afaik it isnt possible to set a variable to superglobal.
Is there any reason why i shouldn't add it to the _SERVER array or any other
superglobal?

Adding Dynamic Values To An Array
I am having a problem adding dynamic values to an array. The values that I want to add to the array are sent via a query string. The array is stored in a session.

the variables are sent like:

?var=test1
?var=test2

How can I send these variables to an array. I tried doing it like this:

$_SESSION['varList'] = '"'.$_SESSION['varList']'",'.$var;

but this only creates one entry in the array which is "test1","test2"

Adding Values To An Array In A Foreach Loop.
I am creating a function for my horse site that will choose the color of the horse. I have a database full of horse breeds and all the possible colors they can be.

Here is what the "color" column might hold for one of the horse breeds:
solid,paint The word "solid" can be a bunch of different colors...so I am trying to make my script add all these colors to an array I am populating that holds all the possible colors for that breed. Here is my current code for the function with comments to let you know what is going on Code:

Adding Different Values
How can I do If I need to add some values, I am using LEFT Join and I am displaying some lists There is my code: PHP Code:

Basic Question - Adding Values
I have a form that contains radio button groups. Each group is assigned a name and each radio button has a numerical value (1,2,3, etc). I want to total the values from each group and forward it to another page which displays that total.

How do I use PHP to take the value from each button group and add them? I can pass each individual answer to the second page ok, I'm just having difficulty totaling those values.

Adding Values In One Column From Query Results
I have this query:

SELECT *,
sum(field_value) as totalValue
FROM table_name
WHERE field_id = $id
GROUP BY field_group

the data type of field value is a decimal value, with values such as 125.00 and 150.50 stored in each record. My goal is to have totalValue be the total value of those numbers. So if I have two records that equal 125.00 and 150.50 totalValue would = 175.50.

the above query does not do this. What do I need to change here? Should I try to do this from the PHP side?

Adding Additonal Values From Forms To The Top Of The Action Page
I have form on multiple pages with one text input and two hidden fields.

When the user submits the form, they are taken to:

/actionpage.php?input=x&hidden1=y&hidden2=z

On the action page there is a third party JavaScript that I can not change that requires the two hidden fields.

I am wondering if I can setup something at the top of the action page that establishes the two hidden fields, allowing me to take them off from all my pages while still allowing the third party script to work.

Comparing User Input Values In A Form With Database Values
I want to compare user input values in a form with my database.
Basically I want to check whether the user exits in my database.
What mysql command can do that?

Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have:

$db = array(); //main array
$db['main'] = array(); //table `main`
$db['main'][] = array('id'=>0,
'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin');
//row
$db['main'][] = array('id'=>1,
'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user');
//row

function trim_value(&$value){
$value = strtolower(trim($value));
}
function fdb_select($fields = "*", $table, $where = false, $limit =
false){
global $db;
$retv = $db[$table];

//LIMIT RESULTS TO FIELDS
if(strrpos($fields, ",") === false){$field=array($fields);}else{$field
= explode(",", $fields);};
array_walk($field, "trim_value");
$all_fields = array_keys($retv[0]);
if($fields == '*'|| is_null($fields)){$field = $all_fields;};
$field = array_uintersect($all_fields, $field, "strcasecmp");
$retvi = array();
foreach($retv as $num =$row){
foreach($row as $fname =$fvalue){
$fname1 = strtolower($fname);
if(in_array($fname1, $field)){
$retvi[$num][$fname]=$fvalue;
};
};
};
//DONE LIMITING TO FIELDS
if($where != false){

//UP TO HERE IT WORKS FINE
//LIMIT TO WHERE CLAUSE
$retvj = array();
foreach($retvi as $num =$row){
//IN THE ROW
foreach($where as $k =$v){
//IF ROW MEETS ALL REQUIREMENTS
if($row[$k] == $v){
$retvj[] = $retvi[$num]; //Keep that row
};
};
};
//DONE LIMITING TO WHERE CLAUSE
};
$retvi = (isset($retvj)) ? $retvj:$retvi;
//SEND A FINAL ASSOCIATIVE ARRAY
return $retvi;
};
print_r(fdb_select("*", "main", array('id'=>"1",
"username"=>"joshfrench")));

the previous code outputs this:

Array
(
[0] =Array
(
[id] =0
[username] =joshfrench
[userpass] =password
[userlevel] =admin
)

[1] =Array
(
[id] =1
[username] =bob_smith
[userpass] =psswrd
[userlevel] =user
)

)

Array (add More Values To The End)
I have an array. I wan to add more values to the end of the array. how would i go about doing this. my current code does not work. PHP Code:

Comparing Array Values
I'm developing a database that holds information about crew members. There are 7 categories of service types. Crew members can be associated with any number of categories.

I'm working on an update form to add or delete categories for a crew member. I first issued a query to find the member's categories. I issued a second query to list all possible categories. I want to show a checkbox for any possible categories that aren't in the member's individual category list. If the member is in categories 1 and 2, but not in 3 or 4, I want to show a checkbox for categories 3 and 4.

I can get the two category lists to print, but I can't figure out how to compare them.

Here is the code I have for the select statements:

Generates the list of member categories:
$cat_query = "SELECT crew_category.crew_id, crew_category.category_id, category.category_desc
FROM crew_category, category
WHERE crew_category.crew_id = "$crew_id" and crew_category.category_id = category.category_id";

$cat_result = mysql_query($cat_query);


Generates the list of all possible categories:
$all_cat_query = "SELECT category_id
FROM category";

$all_cat_result = mysql_query($all_cat_query);


I'm just developing my programming skills (as I'm sure you can tell), so I apologize for my ignorance! Thanks in advance to anyone who can help!

Accessing Values From An Array
i having trouble accessing the values from superglobal arrays. there
are two situations but i'm pretty sure it's the same problem.

here's the deal:

Store Values In An Array
$a=10;
$a=15;

while ($a <= $b)
{
$a++;
}

The output is 10,11,12,13,14,15

How to store the values of $a(10,11,12,13,14,15) in an sigle array.

Shifting Values Up In The Array
i have some values in a text file and im reading it into an array when i unset a value in the array from the middle eg array[2], then i want array[3] and array[4] to shift up keeping the same values. i tried shuffle() and sort() but that rearranges the values. i dont want that to happen. i could not find anything else.

Sort Values In Array?
Does anybody know how to sort through an array so that I would only receive distinct values. For example, if I have an array like this:

Examplearray[0] = apple
Examplearray[1] = orange
Examplearray[2] = orange
Examplearray[3] = pear
Examplearray[4] = banana
Examplearray[5] = banana

I want the output to be this:

apple, orange, pear, banana

How To Get The Values Of An Array Using Javascript
In my php application , I am using an sql query and this query
is returning me a now of rows and I am storing these values in check
box. Here I am using a single check box and declared this to an
array like <input type="checkbox" name="C3[ ]" value="<?php echo
$arr['xx'];?>"and i want to get these checked values using
javascript. but when I am doing
document.formname.C3.checked , it gives me javascript error.

Passing Array Values In Url
I want to pass an array to another php script as follows: Code: echo "<a href="./xxx.php3?value_list=$value_list">xxx</a>"; What would be the correct way to do it?

Filling An Array With A Set Of Values
i know there's a way to fill an array with a predetermined set of values (i.e. 0-999, a-z, etc) but i can't find the right syntax for the task nor find any examples.

How To Get Rid Of Unique Values In Array?
I have an array:
$fruit_arr = array('apple', 'apple', 'banana', 'orange', 'orange', 'orange').

I want to throw away all values which only has a single instance, in this case 'banana'. Is there a more elquent way to do this than the following? PHP Code:

Getting Values In An Array Of Arrays
The following is the output of a print_r on an array. The value of
element[0] is itself an array. How do I access the elements in the
second array?

Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
[Beaverton] =Beaverton ) )

I've tried to set $c[] = $city[0], but this just outputs the same
result.

Save Array Values
I have an array with the following structure

1 => Title: etc etc, Authors: etc etc, Filename: etc etc
2 => Title: etc etc, Authors: etc etc, Filename: etc etc
3 => Title: etc etc, Authors: etc etc, Filename: etc etc
4 => Title: etc etc, Authors: etc etc, Filename: etc etc
5 => Title: etc etc, Authors: etc etc, Filename: etc etc

I have been trying (without success) to save each value as a text file with the title and authors as the content and the filename as the filename. I can easily isolate the needed texts with regex (so don't waste your time on that part) but am struggling with the "foreach" PHP part.

Array For Storing The Values
I have used an array for storing the values but i think it is initializing the array again and again. I am making an application in php in which when a user clicks any other user his particular id gets picked up in an variable and i am putting that value in an array but i want to to append an array means the previous value remains as it is.
I am using this code:

Getting Values From An Array For Flash
I have the following array:

$x[$y][] = array('a' => $a, 'b' => 'b',  'c'  => $c);

And i would like to print all the results for $c so they read something like:

$c[0] = 'toaster'
$c[1] = 'baked potato'
$c[2] = 'tuesday'

(This way i can convert the values to flash varialbes later on) Ive looked at all the basic Array tutorials but have found nothing that matches what Im looking for.

Getting Rid Of Null Values In Array
I have an array :

Array ( => 10078 [9] => 10293 [10] => 10088 [11] => 10237 [12] => 10211 [13] => 10282 [14] => 10300 [15] => 10110 [16] => 10077 [19] => 10063 [21] => 10296 [22] => 10280 [23] => 10082 [27] => 10079 [29] => 10080 [30] => 10301 [31] => 10291 [32] => 10290 [33] => 10294 [34] => 10111 )

i want to be able to keep the same order of the values but i need the index to NOT skip! notice the first array is and then the next one is [9]. how can change this so the array numbers are ,[1],[2],etc.?

Modifying Values In An Array And Then Putting Them In A New Array
How do i get values out of an array, modify them and then put them back into a new array.
I have tried using a foreach to get the values out and to edit them but i don't know how to get them into a new array. Here's the code:

Extracting Values From An Array Session!
I am working in a project to add personal info into DB.

For some fields I use session to keep values before putting them into DB. So I wrote a test code to insert phone numbers into a session and at the end put it into DB.

The problem is, I can wirite into the session but don't know how to extract them, as it's an array. My sesison is writen like this:

/tmp/session_file:

n_array|a:5:{i:0;a:1:{i:0;s:6:"VALUE1";}i:1;a:1:{i:0;s:6:"VALUE2";}i:2;a:1:{i:0;s:6:"VALUE3";}i:3;a:1:{i:0;s:6:"VALUE4";}i:4;a:1:{i:0;s:6:"VALUE5";}}

My code that generates this info is:

Multiple Values In A Form - Array
So the problem is:

I have a form wich passes some values to a new page, the problem is the filed name is ever the same but the values changes. But the value passed is always the last one. PHP Code:

Inserting Values Into The Middle Of An Array
Is there a built in function or easy way of inserting new values into the middle of an array?

Push Values Into An Array While It's In A Loop
Is it possible to push values into an array while it's in a loop?

For example :

$array = array("1","2","3");

foreach($array as $int){
(stuff happens here)
}

Is it possible to push values into $array while in the loop?

Multi-demsion Array Values
I have an array that can be 15 columns by 1 to 5000 rows big. What I need to do is run through a field in the array (manufacturer) to see if there is more than one manufacturer in the array. I dont see a way to do this unless i write a custom function to do it. I am thinking the way would be to pull out manufacture and place them all in an array and then do an array_unique on it and then count the remaining records in the array to determin if there is more than one manufacturer.

Declaring Array In A Form And Getting Its Values
I have this form and I want to store some of the values in arrays. I want a 2 dimensional array. If not possible, 1 will be okay. e.g. $myarray[][];

I want to now use a form and store values in it.
Item 1.1: <INPUT TYPE="TEXT" NAME="myarray[0][0]" VALUE" ">
Item 1.2: <INPUT TYPE="TEXT" NAME="myarray[0][1]" VALUE" ">

Item 2.1: <INPUT TYPE="TEXT" NAME="myarray[1][0]" VALUE" ">
Item 2.2: <INPUT TYPE="TEXT" NAME="myarray[1][1]" VALUE" ">

etc. Is this possible and what is the best way to implement this. The reason I am doing this is because I want to have an SQL statement that goes in a loop manner Code:

HELP! Passing Checkbox Values To Array
I have a form with a repeating table display data from MySQL, ie, invoice numbers and invoice pricing.

I need to be able to select which invoices someone wants to pay via checkboxes. From here, I need to be able to display the corresponding records on another page where I can SUM() the invoice totals to give a price to be paid.

I've never used array's before but believe this is how it should be done. My brain is currently fried and I'm struggling...

Values From Form Via Associative Array
I have a form which has a text field and a select box. There are many other fields also in the form . I need get the value of the text field or the select box, depending on which one has a value. Additionally it has to give the value only from the text field even if there is a selection made from the select box. I know that i can get post values from form like this: PHP Code:

Displaying Prev() And Next() Values From An Array
I have a simple table stored in an array and I want walk through the array and retrieve the current record values, next record values, and previous record values - or each record. I can output the current record values, but is there a way to output the next and previous record values using the Next() and Prev() functions. Code:

ACCESS VALUES WITHIN CLASS WITHIN AN ARRAY
I have the following construct (printed with print_r):

Array
(
[0]=> Classes Object
(
[_my_id] => 001
[_my_name] => John
)
[1]=> Classes Object
(
[_my_id] => 003
[_my_name] => Jill
)
)

What is the syntax to access _my_id and _my_name in for loop.

I have this but it doesn't work:
-for ($I = 0; $I < count($myarrays_name); $I++) {
print $myarrays_name[$I]=>Classes->_my_id
}

Remove Values Less Then 3 Characters From An Array
How to remove values from an array which has values less then 3 chrs. And rearrange it.

Eg.,

Array
(
[0] => an
[1] => a
[2] => and
[3] => more
[4] => or
[5] => less
[6] => equal
[7] => plus
[8] => pause
[9] => stop
[10] => if
[11] => for
)

i want to remove
[0] => an
[1] => a
[2] => and
[4] => or
[10] => if
[11] => for

rearrange the array keys
Array
(
[0] => more
[1] => less
[2] => equal
......

Array Values Not Passing To Next Page
I have a search form which has list box where in the user could select multiple values and a text box for date field.When the user selects multiple selection, the query works fine and displays according to selection only on the first page, but when they hit the next page the query displays the results for all selection.

I 'm displaying 25 records/page. But it works fine for the date field and the next , previous links display according to the date value. I 'm not sure why the value of the array is not passed. PHP Code:

Unique Array Values In Foreach
I have a snippet of code below. In my foreach, I would like to process only
1 item per hdd value, in the case below, the echo $tib['hdd'] . "
"; would
only display 1 and 2, not 1,1,1,1,2,2,2,2. It doesn't matter which one
shows, because I only want the unique value for hdd.

$tibs = array(
"tib1" => array("drive" => "C", "progress" => "on", "hdd" => "1",
"partition" => "1", "compression" => "3", "backup" => "K:"),
"tib2" => array("drive" => "D", "progress" => "on", "hdd" => "1",
"partition" => "2", "compression" => "3", "backup" => "K:"),
"tib3" => array("drive" => "E", "progress" => "on", "hdd" => "1",
"partition" => "3", "compression" => "3", "backup" => "K:"),
"tib4" => array("drive" => "F", "progress" => "on", "hdd" => "1",
"partition" => "4", "compression" => "3", "backup" => "K:"),
"tib5" => array("drive" => "G", "progress" => "on", "hdd" => "2",
"partition" => "1", "compression" => "3", "backup" => "L:"),
"tib6" => array("drive" => "H", "progress" => "on", "hdd" => "2",
"partition" => "2", "compression" => "3", "backup" => "L:"),
"tib7" => array("drive" => "I", "progress" => "on", "hdd" => "2",
"partition" => "3", "compression" => "3", "backup" => "L:"),
"tib8" => array("drive" => "J", "progress" => "on", "hdd" => "2",
"partition" => "4", "compression" => "3", "backup" => "L:"),
);

foreach($tibs as $tib) {
echo $tib['hdd'] . "
";
}

Setting Values In Associative Array To 0
Ive tried almost every combination of while,foreach, key, value ,
array,0 I can some up with

Ive got an associative array that Ive been using as a counter
eg if (blah blah blah )
{$array['beans']++}
elseif (something else){$array['peas']++}
else {$array['carrots']++}

I then want to reset all the values to zero

foreach ($array as $key=>$value)
{ ??????? }
or array_walk ?



Storing MYSQL Values Into An Array
Ive got a basic MYSQL query that is returning data and i want to store it in an indexed array so i can get at the individual values easily. in my code i have used the list() function. Code:

How To Store Checkbox Values To An Array?
I need to allow the user to select multiple mysql records via an html form checkbox.  On submission of the form I would like to store these values in an array for either multiple record deletion or creating a list of records. Code:

Display Values Of Multidimensional Array
Can anyone help me with a function to display the keys/values of a multidimensional array in a more simpler to read display than that of the standard print_r()?

Display Array Values In A Class
I'm trying to diplay values from an HTML mutiple select list in a class. I'm trying to pass the array of selected values in the same manner as the strings in the other sets and gets in the code below. But I don't seem to be getting an array when I try to use getArrayCities. How do I pass the array and display the array values by using getArrayCities? Code:

Unset Empty Array Values
I have a file that I dumped in to an array. I then used strip_tags to remove all the tags from each element. My question is this, how do I get rid of the empy ones?

I tried many different methods that I found on php.net and nothing would work, I just kept coming up with the same array over and over again. Code:

Finding Double Array Values
for a script of mine i have language values in an array. the issue is I found that some things are the same as the other array values. now i have alot of of values in these arrays so going through every one is very tedious. so question is, is there a way to create a loop to check the array values?

Checking A String For All Values Of An Array
If I have an array named $KeywordsArray, and I need to see if all of the values in the array are in a string named $TheString, what is the most efficient way to do this?


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