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.





Count Total Iteration


I got stuck trying to count total iterations for two loops. My code is as follows:

for($i=1; $i<10; $i++){
echo $i;
for($j=1; $j<5; $j++){
echo $j;
}
}
it's gonna produce results as follows:
1 - 1,2,3,4
2 - 1,2,3,4
etc..

How to make this script output:
1,2,3,4,5,6,7..35,36?




View Complete Forum Thread with Replies

Related Forum Messages:
Count The Total Number Of MB Being Used
I`m building a small control panel for one of my sites and what I wanted to do was count the total number of MB being used, is it even possible in PHP and if so what would be the best method?

View Replies !
Get A Total Count Of All Items
I am having a looping issue, when i execute this code I get a total count of all items at the end of each echo.. Code:

View Replies !
Count Total Rows
I have a query and a loop where I output the results. Something like this:

PHP Code:
SELECT
     t1.var1,
     t1.var2,
     t2.var1,
     t2.var2
FROM t1
LEFT JOIN t2 ON (t1.id= t2.id)
WHERE
     t1.var1 = $value

I need to count what's the total number of rows I output.

View Replies !
Count Total Records.
I am currently displaying the Total number of Topics within a Forum, but I dont know how.

Each Topic is assigned to a Forum by inserting the Forum's id which is "ID", (located in forums table), and into a field named idforum, which is located in the topic_fr table.

Now that idforum has the id of the forum it has been inserted into, I can display these in each forum.

I have 2 forums, but I do not know how to display the total number of topics in each forum.

I was thinking something like this, but no.

$query = mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg=id WHERE idtop_msg='$id'");
$number=mysql_num_rows($query);
echo $number;

View Replies !
Iteration/variables
Here's a simplified version of my problem: Let's say I have an html form with five text fields. These text fields are named text0, text1, text2, text3, text4. Clicking the submit button invokes a script called 'process_form.php'.

Now, in process_form.php I need to evaluate each of the variables passed from the html form. For example:

if ($text0 == "blue") {
do something;}
elseif ($text0 == "red") {
do something else;}

If I want to run the same test on each variable, is there a way to do it using a loop or do I have to just copy and paste the above code 4 more times (for $text1-4).

View Replies !
Iteration Through An Array
My data source is a generic XML file. With the help of PHP's SimpleXML I am actually able to parse the XML file into an object/array. Now I like to loop through that array and write the data appropriately into a mySQL-DB width correlative field names, whereas $rss->items contains the data. Code:

View Replies !
'while' Statement: How To Tell It's On Its Last Iteration?
1) Is there a way to know within the 'while' statement's when it's on it's last iteration? The 'while' test is based on a var = 'mysql_fetch_array()'. I want to know when it's in it's final 'true' state (on last iteration) just before it turns 'false'.

The existing script that contains the 'while' is being called from a custom function I've created via an 'include()'.

I only want to run that included script to a certain point, grab the data, then get back to the calling function before that included script goes to the lines following that 'while' which prints the results found. The way the included script is coded, I can break into the 'while' without file editing. Code:

View Replies !
Object Iteration
I am trying to make by classes Iterable by implementing Iterator Aggregate & Iterator interfaces. But whenever my class implemets any of these, I get a Class Not Found error for that class. So, how can I make my class Iterable?

View Replies !
Simple Iteration
Ignoring the print_r below (which is telling me that there is data in $result), can someone tell me why my iteration is not outputing the data from $result?
       
        $excel_row = 6;
        $excel_col = 0;
       
print_r($result);

        $colnames = array_keys ($result[0]);

        foreach ($result as $row)         
        {
    foreach ($colnames as $colName)
           {
       $sheet->write($excel_row,$excel_col,$row[$colName],$colHeadingFormat);
              $excel_col++;
           }           
           $excel_row++;
        }

View Replies !
Last Foreach Iteration
how I can find out inside a foreach if my current value is the last value? Especially when iterating over associative arrays with text keys.

View Replies !
Sequential Iteration Through An Array
How do I go about iterating through a regular array. For example I have an array such as: PHP Code:

View Replies !
Array Iteration Vs. ArrayIterator
Ss ive been researching SPL lately ive read several times that spl will
store only the current element of the underlying collection in memory
during iteration. articles that mention this will say that using these
iterators should afford savings when traversing large collections. well
having found nothing empirical i decided to run some tests myself....

View Replies !
How To Alter Last Iteration In A For() Loop?
Currently I have a for() loop building a query for me. The code is as below
for ($i = 0; $i < count($array); $i++) {

//removes characters in $chars from $array items
$chars = array(" ", "&", "(", ")", "/", "-");
$trim = str_replace ($chars, "", $array[$i]);

$query1 .= "$trim, ";
$query2 .= "'$" . "_POST[$trim]', ";}

$query1 = str_replace ("_1", "", $query1);

$query = "INSERT INTO 2007_results (name, email, ip, $query1) VALUES ('$name', '$email', '$ip'," .  $query2 . ")";
mysql_query($query);

This is producing a $query that looks like this--
$query = "INSERT INTO 2007_results (name, email, ip, query1.1, query1.2, ) VALUES ('foo', 'foo@bar.com', '127.0.0.1', 'result1', 'result2', )";

Obviously that is producing a SQL error because of the extra comma and space inserted at the end of each iteration.  The question is, how to remove the inserted ", " on the last iteration?  There are many more inserted vars as part of $query1; I just shortened it for this example.

View Replies !
Append Iteration Number
I'm drawing a blank on how to append the iteration number to the variable name. PHP Code:

if ( isset($_POST['multi_reg']) ) {
  for ($i=1; $i <= $_POST['multi_reg']; $i++) {
    echo "<LABEL FOR=lastname$i>Last name:</LABEL>";
    echo "<INPUT name="$lastname.$i" value="
    if (isset($lastname.$i)) {
      echo $lastname.$i;
    }
    echo "">";

basically, I ask the user how many people they want to register and then I want PHP to create that many text boxes and assign variables as such:
$lastname1
$lastname2
etc...

what syntax do I use to append the text "lastname" to the variable result $i and use it as a new variable name?

View Replies !
Check If Current Iteration
while iterating over an array i would like to check if I am currently on the last element. Until now I do the following, but I know that it will tragically decrease performance if the array is too big: pHP Code:


foreach ($aPropertiesForBinding as $sCurrentKey => $sCurrentValue) {

    // do something

    if ($sCurrentKey !== end(array_keys($aPropertiesForBinding))) {
        $sSql .= ', '
    }    
}

has anyboda a better idea?

View Replies !
BBCode [quote] Iteration
I have basic code for [quote=name]: '`[quote=(.+?)](.+?)[/quote]`i'
However, when there is a quote within a quote, only the first [quote] is converted. What can I do to solve this without having to call preg_replace again?

View Replies !
Server Friendly Array Iteration...
I'm having some trouble keeping my server alive when iterating through huge arrays to put data in a database. Is there anything less cpu intensive than a simple count and for loop?

View Replies !
PHP MySQL Single Iteration For Data Manipulation
How do I cycle through a MySQL query result one row at a time so that I can
do some work on each individual row, instead of having the whole query
scroll by. I need to have the ability to post each row to a form and then
work on it, posting the results, then go on to the next row.

View Replies !
New Record:Column Count Doesn't Match Value Count At Row 1
I get this error when I try to add a new record to my MySQL Database.

"Column count doesn't match value count at row 1"

So after searching through this forum it seems the problem is that the number of columns in my query doesnt match up to the number of columns in my table. Seems fairly easy to fix doesnt it. However my query has exactly the same number of columns as my table, they are also in the same order. Code:

View Replies !
Column Count Doesn't Match Value Count At Row 1 Error
I keep getting the error: Column count doesn't match value count at row 1

My table has 10 fields, and as far as i can see the only one i am not entering any data into is the vid field, which auto_increment. Code:

View Replies !
Count() - Retreive A Count Of A Column.
I'm performing a select statement against my database

SELECT *, COUNT(column)
FROM blah blah blah
WHERE blah blah blah
GROUP BY member

what i'm trrying to do is retreive a count of a column.

i.e.
$variable1 = $record->variable1;
$variable2 = $record->variable2;
$variable3 = $record->variable3;
$variable4 = $record->COUNT($variable3);

I keep getting the white screen of death, caused by the $variable4 line. How do I retrieve a count? the SQL is correct as I've ran it against the database itself in the sql window. but this has me beat.

View Replies !
Child Class Member's Iteration By Parent Class
I have a class that has a few private members. Is there a way to create a function in its parent class that can access its (child's) private members.

With the following code I am able to get only the public and protected members.

class parentIter {

function iterateProps ( ) {
foreach ( $this as $propName => $propValue ) {
echo "<br>$propName => $propValue" ;
}
}
}

class childIter extends parentIter {
protected $var1 = 'protected var' ;
private $var2 = 'private var' ;
public $var3 = 'public var' ;

function iterateProps ( ) {
parent::iterateProps () ;
}
}
$obj = new childIter () ;
$obj->iterateProps ( ) ;

View Replies !
Total
I have a database table with many entrys, is there a quick way of adding how many entrys there is?

View Replies !
Total ?
I have a table (sales) with 3 columns(id,name,price) the price column is integer,

id = 1
name = Car
price = 10000

id = 2
name = Car 2
price = 15000

I want to calculate the (price) columns in which the total = 25000?

View Replies !
Total Nub
I heard that I'm supposed to set up a database and I can either create it myself with strings of PHP or something like that or I can download something that I'd log into. Now someone point me in the right direction so I can get on my way with learning PHP.

View Replies !
Adding Row Total Value
I have a database with a table called monthlypayment.. 2 fields in that are id, and monthlypayment I need to add monthlypayment for a sum for each id. Id is linked with other tables on the database as well (cars). so if I brought up the monthly payments for car id 12, I need to show all entries, and at the bottom, I need to add them together. "It's right at the end of my fingertips.(haha)" I know this is simple, but I'm drawing a blank.

View Replies !
Total Without And With A Condition
How do I get the total without a condition and the total with the
condition at the same time?

This is my mysql table:

id datetimeconfirmed customerid amount
1 2007-08-14 06:19:03 1 12.25
2 2007-08-06 06:19:19 1 15
3 2007-08-02 06:19:41 2 5
4 2007-08-07 06:19:58 2 7.25
5 2007-08-09 06:36:41 3 25

If I run this query:

select customerid, sum(amount) from test
group by customerid

I get this result:

customerid sum( amount )
1 27.25
2 12.25
3 25

If I run this query:

select customerid, sum(amount) from test
where datetimeconfirmed < &#55614;&#57159;-08-08'
group by customerid

I get this result:

customerid sum( amount )
1 15
2 12.25

Which query do I have to run to get this result?

customerid sum( amount ) total
1 15 27.25
2 12.25 12.25
3 NULL 25

View Replies !
Total Names
I'm need of a mysql query which needs to get the total no. of names in a particular month.

View Replies !
How To Sum A Total Of Amount Using PHP.
how to sum a total of amount using PHP. the data get from the MySQL database. Code:

View Replies !
Running Total
I would like to keep a running total of miles used on a truck. The user will be allowed to enter the total miles on the truck after every use but I want to be able to keep the total miles updating after every user submits their total how would I go about doing this.

View Replies !
Keeping Total
I have a loop that runs through the reults of a query and it does
$tot_feet += $feet(which keeps a running total).

For some reason it will not process 110 rows of data so I had to break it down into three seperate queries with three seperate loops.

I am wanting to keep a sum of all the loops. Im programming I would just create a global variable and use it but how would I do it in php? Since $tot_feet is withing the loop the value cannot be accessed outside the loop due to scope.

View Replies !
Total Value Of Database
Here's my code PHP Code:

$query = "SELECT countries, sum(count) FROM statistics GROUP BY countries";
$result = mysql_query($query) or die(mysql_error());
$num_results = mysql_num_rows($result);

while ($row=mysql_num_rows($result))
{
echo '<p>Total Number of Participants: '.$row['sum'].'</p>'
}

View Replies !
Getting Total Days.
We have a notice form which allows people to tell us if they're going to be for a long time, containing the start day/month/year and end day/month/year. Code:

View Replies !
Total Records
I think maybe I just need a fresh pair of eyes to look at this, this seems like it should be an easy fix, but I can get my head to think about it. PHP Code:

$query1 = "SELECT COUNT(*) as Num FROM COONRAPIDSRECOMMEND WHERE CLOSEDATE > &#55614;&#57156;-01-01'";   
                          if($selectmake ==&#391;'){
                          $query1.=" AND MAKE IN ("".$selectedmakestr."")";
                          }
                          if($selectmodel ==&#391;'){
                          $query1.=" AND MODEL IN ("".$selectedmodelstr."")";
                          }
                          if($selectyear ==&#391;'){
                          $query1.=" AND YEAR IN ("".$selectedyearstr."")";
                          }
                          if($selectcity ==&#391;'){
                          $query1.=" AND CITY IN ("".$selectedcitystr."")";
                          }
                          if($selectstate ==&#391;'){
                          $query1.=" AND STATE IN ("".$selectedstatestr."")";

View Replies !
Total Queries
Say if I have a page that has 5 queries on it, is there a way to calculate that without having to manually write "This page used 5 queries". A way that if I added a 6th query it would automatically update?

View Replies !
Getting Total Number Of Entries
Hello, Im trying to retrieve and echo the total amount of cars in the database with PHP Code:

View Replies !
Calculate Total Of A Column
I have a column in mysql called price, and I would like to total the toal value of all items in that column, how do I do that?

View Replies !
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 !
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 Replies !
Total Cookie Reset
Why is all the cookie being reset when I tell it not to reset the item named sessionhash and userid. PHP Code:

View Replies !
Total Result Php Mysql
PHP Mysql
limit the result to 5
I can display the 5 results using a do & while which it ok.

I want to list the total or all the results without using a do or while

this is so I can combine the results and remove duplicate words from the
total results

I.E.
Do & While
row result
1 this is the top
2 this is the bottom
3 this is the middle
4 this is the end
5 this is the finish

This is what I want to do:
result
this is the top this is the bottom this is the middle this is the end this
is the finish

modified result::
this is the top bottom middle end finish

View Replies !
Counting Total Kb In Directory
im trying to create a script that allow me to see how much space has been used by a certain directory and to calculate this in Kb (kilobytes) or Mb (megabytes), i have search the forum and the web....but can't find anything really upto the job.

View Replies !
Total Login Time
How can I know that when a user is logged in? Like I want to store each login and logout time of each user in a database.

View Replies !
Pagintion Page Of 15+ Total
I have a pagintion page of 15+ total...now I dont to want display all the page numbers. I want something like: Pages: 1 2 3 4 5 ... 12 13 14 15 How would I do this in a for loop?

View Replies !
Finding Cart Total
I have a question concerning my cart total. I need to get the total I have my products and cart in two separate tables: products and cart.

In my cart table, I have stored the productid to tie it to the products table, userid from the session variable to tie the products in the cart together, and quantity. In my products table I have the price for the product. 

What would be a formula I could write to get the complete total dynamically? Because I could have one product up to 20. If you need more info, let me know.

I thought about calculating the individual totals and then adding them, but I don't know how to do that.

View Replies !
Total Table Columns
I have a report that pulls data from a mysql table and generates a html table with the data. I need to sum up the columns into 2 separate  fields  I think I need to access the result from the query but do not know how. Code:

View Replies !
Total Battles Fought
i wanna do a area where it says: total battles fought. i have a table, which stores battle logs with a id, winner, and loser columns. how do i grab the row with the biggest ID number(this way, i can use that as battles fought).

View Replies !
Total Rows By Date
I have a DB that records visits to my site. What I would like is a single SELECT statement that will show total visits in the past day, week, month, year.

I know how to do it for a single category (ie SELECT * FROM Data WHERE Date < NOW() - interval 7 day) but not four at once. I would like to do it without 4 different select statements. And if COUNT () is the answer can I get an example. I can never get COUNT () to work right.

View Replies !
How Do I Get The Total Records From A Table?
It also shows the total submissions. Right now, when you choose to view by a particular topic (for example, select a region - California) the total submissions only shows for those results (which right now is 1). I'd like to show the total results not just for California (which right now is 4). Code:

View Replies !
Total Clicks For Each Image
i have a website with some images and would like to keep track of every click each image receives. i dont don't know how to use php and mysql at all, so i hope any of you can give me the code to insert in my pages or a link with a script to copy-paste in my website. i just need the total clicks for every image.

View Replies !
Total Space Left
im writing a file management system, that allows members to upload files, each member is assigned a user level which has a specific Quota of space on the server, what i need my script to do is show the total amount of space currently used. Code:

View Replies !
Finding Total Weekends
how can i get total weekends falling in the current year.

View Replies !

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