Adding Data To An Array

Mar 12, 2007

I'm trying to make a simple shopping basket script, but am a little unsure of the best way to do it. I want an array where items can be added/removed with a simple form and displayed as a list, but I'm a little unsure how to go about doing it. Code:

ADVERTISEMENT

Storing A Multidimensional Array As An Object Variable - Adding Additional Keys To The Array?

Dec 20, 2010

So I have a multidimensional array which is stored in an object. I want to add additional keys to this array. Here's what I have:

$object->pathsArray = array(
"key1" => array('path' => '/some/path/to/some/file.php', 'action' => 'index'),
"key2" => array('path' => '/some/path/to/some/class.php', 'action' => 'method2')
);

And here's what I assumed would work but did not:

$object->pathsArray['key3'] = array('path' => '/some/path/to/some/method/or/script.php', 'action' => 'method3');

[Code]...

So my question: Is there a simpler syntax (ie: one line solution) or am I forced to bring in a temp. variable, append to that then merge/re-assign the value to the object?

View 1 Replies View Related

Adding Checkbox To A Combobox / Checked Values To An Array And Then Use The Elements Of That Array In Mysql Query?

Jun 5, 2010

I want to add check boxes inside a combo box and then use the values of the checked boxes in my sql query.

Also I need to append the checked values to an array and then use the elements of that array in my sql query.
How can I proceed?

View 1 Replies View Related

Adding An Element To The Beginning Of An Array Without Changing Other Array Keys?

Sep 7, 2010

How can I add an element to the beginning of array without changing array key values in PHP?

View 7 Replies View Related

Array Push - Adding An Elements To An Array With A Specific Name?

Jan 6, 2010

Hopefully a simple question. I have an array with the following structure:

PHP Code:
Array
(
[0]=>Array
(
[id]=>6
[userid]=>1
[date]=>January6,2010,5:17PM

[Code]...

View 2 Replies View Related

Adding To $_POST Array Is Not Reflected In $_REQUEST Array

Nov 7, 2007

Recently I wrote this:

<? echo 'action = '.$_REQUEST['action'].'
'; ?>
<?php $_POST['action'] = 'newmember_split'; echo 'action = '.$_REQUEST['action'].'
'; ?>

My expected output was:

action =
action = newmember_split

However my output was:
action =
action =

How is this so. As far as I know $_REQUEST is supposed to reflect both $_POST and $_GET. I tried to find some information on it but failed.

View 10 Replies View Related

Adding An Array Inside An Array In A Function?

Apr 7, 2010

I have created a function in PHP that calls a webservice and parses through the result, assinging values to variables and returning them all as an Array. This all works perfectly, however I have come across a need to have an "array within my array"I am assigning values as below:

$productName = $product->Name;
$productID = $product->ID;
$productArray = array(

[code]...

View 1 Replies View Related

Adding Array Key Multidimensional Associative Array?

May 31, 2011

I am having problems updating a deeply nested multidimensional php associative array.what I basically want it to add and 'parent_id' key with an incrementing value to all array elements that has an array under them.

For example i have the array below.

[root] =>
Array('child_1' =>
Array('child1_grandchild_1' => 'gchild1_value',
'child1_grandchild_2' => Array('grandchild_1' => 'gchildval1',
'grandchild_2 => 'gchildval2',
'grandchild_3' => 'gchildval3'),

[Code]...

View 1 Replies View Related

Adding A Value From MySQL Query Array Into A Array?

Nov 25, 2010

So I'm querying my database to add the results (mapID's) into a PHP array. The MySQL query I used in the below code would usually return 10 values (only 10 mapID's in the database)

Code: [Select]while($data = mysql_fetch_array(mysql_query("SELECT mapID FROM maps"))){
$sqlsearchdata[] = $data['mapID'];
}

Instead the page takes ages to load then gives this error: QuoteFatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 16 bytes)It says the error begins on the first line of the above code. I'm assuming this is not the right way to add the value from the MySQL array into a normal PHP array.

View 4 Replies View Related

Adding To An Array In Multidimensional Array?

May 29, 2009

I have a Multidimensional array.

PHP Code:
$playerid = 5;
$finaldraft = array();
$playerchoice = some number pulled from the database
$finaldraft[] = array($playerid, array($playerchoice));

This store the information properly, but later on in the code I need to add onto the array inside the first one. I can't figure out how to add onto the interior array. Ive tried running

[Code]...

Does this even make sense. Let me know if it does not and I'll try to explain it another way.

View 2 Replies View Related

Array And Adding

Jun 8, 2005

i have lots of values in my sql table, i need to collect all the values from each row and retireve them in an array, then find the average of this array. PHP Code:

<td width="122"><strong>Average Bid:</strong> <?php $getprices = mysql_query("SELECT * FROM bids WHERE project='$id'");
  
function add_array($array)
{
for( $i = 0; $i < count( $array ); $i++ )
{
  $total_array = intval($total_array) + intval($array[$i] );

can anyone see the problem?

View 9 Replies View Related

Adding An Array

Feb 15, 2006

Is it possible to add an array variable and a variable together? What I have is a for statement where $i runs from 1-10. Inside the for statement I have an array variable $row['hometeam'].

What I need to do is add $i to $row['hometeam'], i.e

PHP Code:

$hometeam = $row['hometeam''.$i.''];

... so I end up with $hometeam = $row['hometeam1'] through to $row['hometeam10']But I dont think the above code will work.

View 2 Replies View Related

Adding Up An Array

Mar 11, 2006

i have an array, which holds a total of 10 items, and i would like to add them all up to give me a total. what is the best way to do it, i have tried with the FOR, etc, but cant seem to get my head round it?

View 1 Replies View Related

Adding To An Array

Jan 15, 2006

I have the following code: PHP Code:

if (empty($zips)) echo 'Error: '.$z->last_error;
else {
   foreach ($zips as $key => $value) {
      echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>93001</b>.<br>";
      $getcity = "Select city from zip_code where zip_code = '$key'";
      $resultgetcity = mysql_query($getcity);
      $resultsetgetcity = mysql_fetch_array($resultgetcity);

View 5 Replies View Related

Adding A Value To An Array

Nov 20, 2009

Adding a value to an array. Why won't this work?

Code: [Select]$notify_list=file($filename);
$notify_list = array_push($notify_list,"$user_em");
foreach($notify_list as $key => $val) { echo "$val<BR>"; }It prints the number of records.

the file() is clearly an array and foreach prints as expected. I wonder if it is something to do with the at the end of each line? I could easily loop and manually build the new array but....

View 3 Replies View Related

Adding Rows To An Array / Insert Blank Rows Into The Array For The Missing Days?

May 24, 2010

I have loaded an associative array of records from a MySQL database table.

The array consists of 1 to 7 rows representing one week of entries,which might not have been entered for each day.

How can I insert blank rows into the array for the missing days so that I can easily display the data in a table?

I don't need to update the database with the blanks.

Example:

Field1 Field2 Field3 Field4 .... Field#
Record[0]
Record[1]
Record[2]
Record[3]
Record[4]
Record[5]
Record[6]

Field4 is the date as yyyy-mm-dd

I load the array automatically using a start date and end date

Some weeks there will be a Sun, Tue, and Fri or Mon, Tue, Wed, Fri & Sat.

View 3 Replies View Related

Adding Onto Array Login.

Feb 16, 2003

I have a login screen (login.html) that posts to login.php which confirms if the username is valid or not then redirects them to welcome.php. Without making a cookie, is there anyway I can maintain the username they typed in and use it in welcome.php? I tried doing anther form action = "welcome.php" in the login.php page with no luck. Maybe I am just doing it wrong...help? It can be viewed here.

View 13 Replies View Related

Adding Values To An Array

Aug 25, 2006

I have a script that uses foreach() like this:

foreach ($var1 as $var2) {
$statsarray=array(1 => $stats);
print_r(array_values($statsarray));
}

It goes through the foreach right and the print_r displays all the different stats, but there are in separate arrays, and I need them to be added together so they are all in the same array?

View 1 Replies View Related

Adding Items To An Array

Jul 17, 2005

I have a for loop to add items to an array, but when i use a for loop to print these items, iI only get the last item of the array. This is a simplified example of what i do, what is wrong with it:

for ($i=0;$i<10;$i++)
{
$test=array($i=>$i);
}

for ($t=0;$t<10;$t++)
{
echo "array".$t."= ".$test[$t]."<BR>";
}

View 2 Replies View Related

Adding Values Of An Array

Nov 24, 2006

Here is the problem i am facing. I have a loop displaying a number filed from my db. PHP Code:

$sql = "select * from amount";
           $query = $DB->Query($sql);
           $count=mysql_num_rows($query);

                       for($i = 0; $i < $count; $i++)
                          {
                            $j=$i+1;
                             $item = mysql_fetch_assoc($query);
                           echo "<table><tr><td align=center>".$j."</td>";
                         echo"<td align=center>".$item['bsal']." </td>";
                         echo"<td align=center>".$item['ta']." </td></tr></table>";

                        }

View 2 Replies View Related

Adding Up Value Of Array And Getting The Average?

Jun 2, 2010

I have an array that looks similar to this,

[4] => Common_Model Object
(
[id] => 4
[name] =>
[date_created] =>

[code]....

I wanting to add up the [rating] and get the mean average. But I dont know how do this with PHP, my attempt looks like this,

<?php
foreach ($rt as $rating) {
$total = $rating->rating + $rating->rating

[code]......

View 2 Replies View Related

Adding Like Values In An Array?

May 17, 2010

add a specific value of items in my array that have the same itemid.If a customer adds two of the same item to the array I want to change the quantity of the item to 2 and list it in the array once instead of having the same item in the array twice.I tried doing some stuff with array_search, but with no luck.Here is what I have for variable:
PHP Code:
if ($_REQUEST["thisitemid"]!="") {
$key=md5(time());
$cartitems[$key]["itemid"]=$_REQUEST["thisitemid"];

[code]...

View 1 Replies View Related

Adding Up Numbers In Array?

Sep 11, 2009

I am trying to find the sum of product's weight and can't seam to find anything. I have included my code snippet below.

Quote ...
$totalweight = 0;
foreach($_SESSION['ddc']['productsincart'] as $key => $value) {
$sql = "SELECT * FROM ddcart_products WHERE id = '".$key."'";
$result = mysql_query($sql);

[Code].....

How can i add up and display the total weight ($weight) for everything listed?

View 2 Replies View Related

Adding One Character To Each Array Key?

May 13, 2011

Fastest way to add prefix to array keys?

I had a quick question about arrays in PHP. I need to add a couple of characters to each key in an array, for instance:

name => Mark age => 23 weight = > 150

needs to be converted to:

r_name => Mark r_age => 23 r_weight => 150

View 3 Replies View Related

Adding A Key & Value To All Arrays Within An Array?

Oct 22, 2009

I would like to take this:

$arr = array(
array("top"=>10, "left"=>10),
array("top"=>50, "left"=>30),
array("top"=>60, "left"=>70)
);

[Code]....

Right now I'm looping through with a foreach loop. Is there a better way? The key/value can are always going to be the same.

View 1 Replies View Related

Adding A Link To A Array?

Jul 30, 2009

ok now i am stuck got this done in php code so no table but how can i add a link to the name in the arays

<?php do { ?>
<tr>
<?php

[code]....

View 14 Replies View Related

Adding Array To Database?

Oct 9, 2009

i have an array with max 10 users i want to add them to the members table each user needs to have +1 to the vote field aswell if one of the users exists it just have to have +1 added.

View 5 Replies View Related

Adding Dimensions To An Array?

Jul 27, 2009

I have a .csv file that I need to split into records.

Basically, each record is one line, and each line has multiple pieces of data.

So, my plan was to explode the file into an array of lines, and then explode each of the lines into a second level of the array.

There might be an easier way of doing this, but I am trying to get a nice ordered array of the data in the csv file.

View 4 Replies View Related

Adding Values In An Array?

Mar 16, 2011

How can i add all of my array values together in PHP?

I would like to add the numbers up in the array $m[2] for a total number of players online.

Whats the simplest way to do that, so I have the variable $total?

$c = curl_init();
curl_setopt_array($c, array(
CURLOPT_URL => 'http://www.bungie.net/stats/reach/online.aspx',
CURLOPT_RETURNTRANSFER => true,

[Code].....

View 1 Replies View Related

Adding To An Array In A Loop?

Mar 10, 2010

Created an array, and add to the array inside a while loop is this possible?

Code:$data = array();
while ($var=mysql_fetch_array($var2))
{

[code]...

Add to the data array.

View 6 Replies View Related

Adding To Multidimensional Array

Oct 31, 2007

I'm realtively new to PHP and I'm trying to get my head around a particular issue. I've got an array that looks like this:

$field_array = array (
array (field=>"dist_Company", type=>"text"),
array (field=>"dist_Active", type=>"select", options=>array(array(oname=>"yes", oval=>"1"), array(oname=>"no", oval=>"0"))),
array (field=>"dist_CompanyID", type=>"select"),
array (field=>"dist_Shipping", type=>"text")
);

What I'm trying to figure out is how to add to this array after it's been defined. In this case I'm trying to add the "options" subarray to dist_CompanyID element so that it has options similar to those predefined in the dist_Active element.

I can do it if I specify the index like this:

$field_array[2]['options'][] = array(oname=>"one", oval=>"1");
$field_array[2]['options'][] = array(oname=>"two", oval=>"2");
$field_array[2]['options'][] = array(oname=>"three", oval=>"3");

Is there some elegant way to find the index number for the element containing field=>"dist_CompanyID"?

View 2 Replies View Related

Adding To An Array - While Statement

Jul 30, 2007

You know how you can do this:

array("#ff0000","#ff8800","#0022ff","#33ff33")

Well how could i set it up so that in a while statement it adds to the array? And if its possible how can i make it add a random color (#ff0000 etc.);
Any ideas?

View 3 Replies View Related

Adding To Start Of An Array?

Jun 22, 2007

I know I can achieve it by using an array_reverse, followed by adding the desired first element to the end, followed by another array_reverse - but wondering if there is a simpler/quicker way of doing this? Code:

View 3 Replies View Related

Adding Values To An Array?

Nov 14, 2007

I am trying to add the property_id to an array every time the page is loaded. So if fav is set, I want to add the is of that property to an array and hold that array in a session.

This is wrong but its what I was trying...

$property_id = $_GET['property_id'];

if(isset($_GET['fav']))
{
$faves = array ($fav);
session_register('faves');
}

View 4 Replies View Related

Adding Values Of Array Together?

Sep 27, 2010

add the values off all results in the $pamount array?

Code: [Select]$result2 = mysql_query("SELECT * FROM pobook WHERE jobnumber = '$jobid'");
while($row2 = mysql_fetch_array($result2))
{

[code]...

View 10 Replies View Related

Adding To An Array With A Function

Feb 14, 2011

im having some trouble when i try to add values to an array from a function. The added value will not stay saved. fun1 will display both firstname and surname but when i call fun2 after calling fun1 i just get the firstname. I would like to have it so the array is updated and stays updated untill it is cleared or over written.

<?php
class Test extends Controller
{
var $data1 = array(
'firstname' => 'craig'
);
function fun1()
[Code].....

View 1 Replies View Related

Adding An Integer Into An Array?

Aug 1, 2010

adding an integer into an array

something like this

$Loaded[count($Loaded)+1]=$To;

View 2 Replies View Related

Adding Values Onto An Associative Array...

Dec 3, 2002

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:

View 1 Replies View Related

Adding Sums Of Array Values

Jul 15, 2004

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.

View 1 Replies View Related

Adding Only Unique Items To An Array

Mar 3, 2006

I've made a small code snippet that adds a new item ($value = $_GET) to an array in a cookie. My main question is in the title of the post, and I have a related one: How do I delete a specific value from the array and shift all the other values down to fill its place? Will this happen on its own? And one more: Using this code I display the array values in descending order;

foreach ($_COOKIE['best'] as $name => $value) {
$best = urlencode($value);
echo //insert code here
}
}

Is there any way to display this in ascending order?

View 1 Replies View Related

Adding Values To A Superglobal Array

Jul 16, 2005

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?

View 1 Replies View Related

Adding A Entry Into A MultiDimensional Array

Sep 29, 2007

I make an SQL call to a DB and gather some info. In the following case, I have 2 elements in the array (HERO_ID #1 and #2) I then want to add a third element to to the array, but I just cant seem to grasp the concept. I always seemed to have trouble grasping the concept of arrays in programming classes for some reason. Code:

View 6 Replies View Related

Dynamically Adding To Multidimensional Array

Dec 16, 2005

$sql= sql query
$i=0;

while
($a2=mysql_fetch_array($a1)){array_push($temparray ,$a2[0],$a2['ad'],$a2[1],$a2[1]);
{
I want this array to be the value of an asssoc. array $results[$i]
$results[$i] =$temparray doesnt work
$results[$i] =$temparray[] doesnt work
$results[$i][] =$temparray doesnt work
$results[$i] =>$temparray doesnt work

then $i++;
}
so what does ?

View 4 Replies View Related

Adding A Custom Object To An Array

May 7, 2006

Anyone have any idea what im doing wrong here:

$image = new Image();
$image->SetImageContent($imageRow['imageContent']);
$image->SetFileSize($imageRow['fileSize']);
$image->SetFileName($imageRow['fileName']);
$image->SetImageId($imageRow['imageId']);
$image->SetParentImageId($imageRow['parentId']);
$image->SetFileType($imageRow['fileType']);
$image->SetImageHeight($imageRow['height']);
$image->SetImageWidth($imageRow['width']);
$image->SetIsThumbnail($imageRow['isThumb']);
$this->mImages[$this->mImageCount] = $image;

where Image is a custom class and mImages is an array declared as
follows:
$this->mImages = array();

Whats happening is im executing this function
function GetImage($imageIndex)
{
return $this->mImages[$imageIndex];

}

and then trying to call a member function on the returned value
i.e.
$image = $album->GetImage(1);
$imageId = $image->GetImageId();

and im getting this error" Fatal error: Call to a member function on a
non-object in
/home/flyerweb/public_html/ImageManipulator/POCPages/DisplayAllImagesInAlbum.php
on line 30"

View 3 Replies View Related

Adding Elements To An Array Through A Function

Aug 16, 2006

I'm trying to add elements to an array using a function. I have the following:

$error = array();

function add_error($error_message) {
global $error;
$error[] = $error_message;
}

function show_error() {
global $error;
var_dump($error);
for($i = 0; $i < sizeof($error); $i++) {
echo $error[$i];
}}

I'm using other functions to validate data, and if I `return false`, I do `add_error("error message");` to add an error message to the error array. And I do `show_error();` to loop through all of the error and show them.

Any ideas as to why I can't seem to add elements to the error array?

View 2 Replies View Related

ADVERTISEMENT