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.





SUM Of Array - Total Of All Values


I have an array filled with data. I need to sum it's value.

example: $key1=>10, $key2=>15, $key3=>5

I want the total of all values which should be: 30




View Complete Forum Thread with Replies

Related Forum Messages:
CALCULATING Row Values To Get A Total
My problem is,, that i have a PHP script that displays a table

the table has the following colums

firstname,surname,boots,hospital,woolworths,br,other, total

the firstname and surname are grabbed from the database when the page loads, what i want is for the user to enter values in the boxes under the colums boots,woolworths,hospital etc

then when they click submit,the page is refreshed, data submited into the database, bu them redisplayed in the table the values are calucated and each user is then given a total number of hours worked at those places.

im really stuck guys, havent a clue how to go about this.

so an example would be

F S boots Hospital woolworths other total
JOE BLOGS 0.8 0.8 0.8 0.8
HELP me 0.1 0.5 0.5 0.5

submit is pressed, data entered into the database, then page redisplayed with the total column totaled up.

F S boots Hospital woolworths other total
JOE BLOGS 0.8 0.8 0.8 0.8 3.2
HELP me 0.1 0.5 0.5 0.5 1.6

View Replies !
Total Of Values In A Single Column
I'm trying to retrieve the total of all values in a specific column. I know that I can use some version of "SELECT SUM" to gather the info, but I can't figure out how to convert it to a variable. Here's what I have so far:

<?php
$scoreTotQuery = "SELECT SUM(score)
FROM
pc_complete";
$scoreTotResult = mysql_query($scoreTotQuery);
?>


I want to be able to retrieve the total of all scores that have been recorded, so that I can display the average score.

View Replies !
Getting Total Of 2 Values Seperated By Space
i have a DB and which has a field called rates. in rates i have 2 values stored by using a space in between. i.e 45 65

i just need to TOTAL the 2 values in the field, when i PHP a total i only get the 45, it does not read the space and misses the 65. i need to be able to total them both and get 110.

View Replies !
Use Preg_replace To Replace Values In A Template XML File With Values From An Array.
I am trying to use preg_replace to replace values in a template XML file
with values from an array using the following:

$tmp = preg_replace('/<!-- (S+) -->/ge', $values[1], $line);

The template file will have lines such as:

<image source="pics/<!-- pic1 -->" thumb="pics/<!-- thumb1 -->"
title="<!-- caption1 -->"/>

And the $values array has values:

$values[pic1] = "raj1.jpg"
$values[thumb1] = "traj1.jpg"
$values[caption1] = "Who is this?"

Can anyone see where I am going wrong?

View Replies !
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 Replies !
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
)

)

View Replies !
Accessing Array Values Inside A Multidimensional Array
I need to access a value which is inside in a multidimensional array...

Suppose there is a form and where I takes all the form values inside an array named access..and I post the values into a different array.

$registrationArray = $_POST['access'];

Now I need to loop through this registration array and get values printed to the new variables...

Suppose this is the array $access = array (fname,lname,date,year,month)

How do I print the date,year,month values into different variable by looping through registration array..

View Replies !
Trying To Compare Array Values To A Value, Then Create Boolean Array
I have an array that returns data like this (see array below) The array[0] contains all the votes for one story as well as information that pertains to that vote, and the array[1] contains vote information for another story. What I need to do is check is a user_id stored in a session, is in the array, and then create a boolean array from that.

For example, here I want to check if the user_id is featured in the first set of data, let's say my user_id is 74. Ok, so it is in the first set of data, so we set the boolean variable to true. Next I need to search the second data field for my user_id, 73. It is not featured here so the value in my array is set to 0.

I need an array that returns values either 1, for true, your user_id was found in the table, or false, for your user_id was not featured in the table. They need to be in order of the story too. I'm having trouble one comparing the two variables against eachother, since the array is very deep, and two, creating the array on the fly. Code:

View Replies !
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:

View Replies !
Sort The Array By The Values In Array[$i][0]
How would I go about sorting the following array, I've been looking at array_multisort but to be honest I'm either not fully understanding it or it's not capable of what I'm trying to do.

What I'd like to do is to sort the array by the values in array[$i][0] but I can't figure it out, the values being zzzz,a0,a1,00000000000000. PHP Code:

View Replies !
Copy Values From Array In To New Array?
I have an array with the following values in it:

REC_DATE = 'abc'
REC_CREATE = 'abc'
REC_DONE = 'abc'
DATE = 'abc'
TEST = 'abc'

Now I would like to put all the values which are starting with REC in to another array, what would be the best way to achieve this?

View Replies !
Get The Sum Of The Array Key Values.
I want to get the sum of the array key values.

ex: $key1=>10, $key2=>15, $key3=>5

I want variable $sum = 30.

any solution?

View Replies !
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:

View Replies !
Use The Values From The Array
First I define an array and assign 65 values to it from a mysql database. Using print_r (array_values($arr_anmref)) I can see all the values and they are correct so no problem there.

I then need to process the information from a form when the users clicks ok. (This is to update the records based on if the user has checked or unchecked a checkbox).

When the user presses the OK button they are taken to a new page where I want to process the form and show the results of the processed information.

However in the code I need to use the values from the array but its misfiring.

The array is now empty and

print_r (array_values($arr_anmref))

.....shows nothing

I have tried adding session_start() at the top of both pages but to no avail.

View Replies !
How Many Values Is In One Array
if theres a way to know how many values is in one array. What i'm doing is, using a while query which stores an ID of an item in the value of a checkbox and the checkbox name is "name[]"

This turns it into an array, so i was wondering if i could count how many items actually are in that array?

View Replies !
Array Values
I have an associative array called "$infoDivs". I want to do something like the following: PHP Code:

$var = $var . $infoDivs[value1] . $infoDivs[value2];

The problem is, that the array has over 20 values, and is liable to get more at any point. I would like to just say. PHP Code:

$var = $var . ALL VALUES OF $infoDivs;

I would like PHP to do this (^) for me, I'm thinking that I could use a loop, but I'm not very good at them . How should I go about doing this?

View Replies !
Values Into Array
I am trying to combine JavaScript snippet wtih my PHP code. As a final result i need to get the following array:

PHP Code:

mytext[0]=""
mytext[1]="My text 1"
mytext[2]="Another text line"
mytext[3]="Yet one more"
mytext[4]="And another"

Now, I can run a loop and get the actual values in the string like:

PHP Code:

foreach ($myString as $str) {        
$str = $pr->myvalues;
}

Having difficulties combining the two together.

View Replies !
Values In Array
I have the following array:

$affiliations = ('Name1,Company1,City1,Country1', 'Name2,Company1,City1,Country1', 'Name3, Company2, City2, Country2');

I want to be able to detect in the array that Name1 and Name2 have the same company, city & country.

View Replies !
Values Into Array
i have a form, which has triple drop down lists which populate depending on the previous selection using javascript, an input text box, and a checkbox. the purpose of this form is to allow a user to create a phone package, now a user can create more than one package, however only one form is displayed, is there a way i can submit one form into an array and display that underneith on the same page and blank the form to add another package.

View Replies !
Values Into An Array
I've got this dymanic form that, I need to take the values of the selected checkboxes and puthem into an array. Here's my form: PHP Code:

foreach ($inputArr as $key => $value) {
  echo "<input type='checkbox' name='$key' ";
  if (in_array($key, $checkedArr))
    echo "checked='checked' ";
  echo "/>$value
";
}

PHP Code:

$new_array = array($_POST[$key']);
$info = implode(",", $new_array);

View Replies !
Add Values To Array
My arrays look like this:

1 , 3, 5, 6, 7, 8 ,9 ,12, 14, 16, 17

I need it to be filled from 1-17. Is it possible to add a where each number is missing. The missing numbers are random. So by adding a dash, it would then look like this:

1, -, 3, -, 5, 6, 7, 8 ,9, -, -, 12, -, 14, -, 16, 17.....

View Replies !
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!

View Replies !
Reusing The Array With A Different Set Of Values.
Is there any way that after filling the array in a loop with values that i can go back and start filling in the same array from scratch with a different set of values.

View Replies !
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:

View Replies !
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.

View Replies !
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.

View Replies !
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

View Replies !
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.

View Replies !
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?

View Replies !
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.

View Replies !
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:

View Replies !
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.

View Replies !
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.

View Replies !
Extracting Url Values In Array
I need to extract range-url values in an array. The range-url may contains multiple range.

Code:.....

View Replies !
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:

View Replies !
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.

View Replies !
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.?

View Replies !
Adding Values To An Array
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 Replies !
Export Array Values To Csv?
i would like to know how to export the data in .csv format?
suppose i had an array holding values:

[PHP]$data_arr[$i][0] = "xx";
$data_arr[$i][0] = "xx";
$data_arr[$i][0] = "xx";
$data_arr[$i][0] = "xx";[/PHP]
where $i varies from 0 to n

I would like to export this data in .csv format,
how could this be accomplished?

View Replies !
Check Values In Array
I have constructed an aray with x values, how can I check if all values are the same? I want to check if or if not values are same and get the appropriate message.

View Replies !
Getting Values From Complex Array
I have array(5 10 15, 10 25 35, 18 65 44) each value holds multiple subvalues i need to do a comparison for each subvalue within a value. like:

if 5 > 90
or if 10 > 90
or if 15 > 90

then move to the next value and do the same is this possible?

View Replies !
Counting Values In Array
Example of what im kinda looking for:

$array1 = array("1","2","1");
$get = count(in_array("1", $array1));
print("$get");

problem is its only returning 1 and there is clearly two "1"'s in the array. anyone know how i can solve this?

View Replies !
Transferreing Array Values
I need to find a way to transfer all the values of an array inside a function out of the fuction into another array. IE

function splice($filename){
if(file_exists($filename)){
$value=array("0"); // clear the array.
$rows=file($filename); // break text file into a rows array
for($num=0;$num < count($rows); ++$num){
$column=split(";",$rows[$num]);
$value[$num]=$column;}}
return $value;
}

$array1 = splice(file.txt)

Example file data would be

data1;an1;bc1
data2;an2;bc2
data3;an3;bc3

How do I go about getting the function to pass all it's data to the variable $array1?

View Replies !
Checking All Array Values
Anyone know of a function that will check if all the values of an array are grather than or equal to 0? So all values are positive?

View Replies !
Get The Key From The Array Values That Are In Sequence
What I'm trying to do is get the key from the array values that are in sequence, like 1,2,3, 4... or 7,8,9... I'm able to do it just with two keys as you can see here:
PHP Code:

$spots = array("1|250x60","2|120x60","4|250x60","6|120x60","7|120x60","8|120x60");

$c=count($spots);

//First I explode each item on the array and divide them into 2 arrays, one for the spot number and the other for the banner size Code:

View Replies !
How To Get The Count Of Values In An Array
How to get teh count or values which are in an array. for example in the following array it has 5 values in it. so the count is 5. Like that in an array how to find out how many values are there Code:

View Replies !
Export Array Values To Csv
i would like to know how to export the data in .csv format? suppose i had an array holding values:

$data_arr[$i][0] = "xx";
$data_arr[$i][0] = "xx";
$data_arr[$i][0] = "xx";
$data_arr[$i][0] = "xx";
where $i varies from 0 to n

I would like to export this data in .csv format, how could this be accomplished ?

View Replies !
Array - Check For 3 Values At Once
I take a value and search my database. I then count how many rows are returned. What I want to do is take those returned values and run them against the database to find new values. Example

Value A = Value x =  Value B
                            Value C
                            Value G
              Value y=  Value M
                            Value P
              Value Z = Value O
So how would I check for 3 values at once? 
$level_2 = @mysql_query("SELECT member_id FROM center WHERE upline_id=[i]my 3 values[/i]);}

View Replies !
Get Values Of A Field Array
I have this 10 input texboxes made by a FOR Loop. how can I get their input values?

Here are my codes:
Given: Inside a table

for ($i=1;$i<=10;$i++) { ?>
<tr>
<td>
<input name="date_range" id="date_range" type="text" tabindex=&#391;' size=&#3911;' maxlength=&#3911;' readonly value="" > <img src="images/calendar.png" alt="Date From" id="txtDateFromTrigger" align="absmiddle"></slot></td>
<script type="text/javascript">
Calendar.setup (
{
inputField : "date_range", // ID of the input field
ifFormat : "%Y-%m-%d", // the date format
button : "txtDateFromTrigger" // ID of the button
....................

View Replies !
Loop Array Values
how to loop the values from an array into an sql query. I'm quessing you do this with the foreach function, but I'm pretty lost at the moment on how to accomplish it. I have the below code, which will look at each row in a table, and echo that field's info into array, giving me values of 10, 12, 31, etc. for each row. I want to compare those values with another table, but not sure how to proceed.

// Gets all the player capitals
$sql = 'SELECT capitals FROM game_141 WHERE id >= 2'
$playerdata = mysql_query($sql);
while ($row = mysql_fetch_assoc($playerdata)) {
$capitals = $row["capitals"];
$capitals = explode(",",$capitals);
print_r($capitals);
echo '<br />'
}

//Compare each array value to the country id
$sql = "SELECT id, name FROM countries WHERE XXXXXX"//Not sure how to proceed
$q = mysql_query($sql);
while ($a_state = mysql_fetch_assoc($q)){

$STATES[$a_state['id']] = array('name' => $a_state['name']); //
}
print_r($STATES);

View Replies !
Excluding Values In An Array
I'm trying to exclude variables in an array from my query. (need it to display latest threads a user posted in, excluding threads he started, cause i'm showing those seperately). This is my current code: PHP Code:

//Mythreads Latest you posted in
$Recordset2 = mysql_query("SELECT DISTINCT `topic_id` FROM `phpbb_posts` WHERE `poster_id` =2
AND `topic_id` != '$id' ORDER BY `post_time` DESC LIMIT 0 , 4") or die(mysql_error());
$blue = 0;
while ($results = mysql_fetch_array($Recordset2))
                    {

                                $id[$blue] = $results[topic_id];
                             $title[$blue] = $results[topic_title];
                             $blue++;        
                             if ($blue == 5) break;
                    }
$Recordset2 = mysql_query("SELECT * FROM `phpbb_topics`") or die(mysql_error());.......

View Replies !
If An Array Contains Empty Values
I send a form via POST method, the form contains an uncertain number of fields, so I use an array (let's say email[]). After sending the form, I would like to check if the array contains empty values. Naturally, if($_POST['email'] == "") does not work even if all the fields are empty. So, I use a foreach loop to check if the array contains empty values:

$email = $_POST['email'];
foreach ($email as $key => $value){
if ($email[$key] == ""){
echo "field contains empty value";
}
}

is there any other way to check if all the items in an array contain empty values?

View Replies !

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