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




Counting


I have looked up count() and sizeof() but they're not quite what I'm looking for ...

I'd like to open a text file using PHP, which I know how to do, and count the number of instances of a string, which I don't know how to do!

There are in particular 6 types of string. I'd like to count the total of each and use each total to form the data for a graph.

This is irrelevant to my query, but for anyone interested, I'm using the JavaScript graph builder library at:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Row Counting
I'm using LIMIT in my SQL query to create a paging effect for a gallery. I need to count the total number of rows in the table, but I'm having a problem.  Instead of giving the number of rows, it simply returns the word "Array". Code:

Counting
I have the following query

SELECT COUNT(*) as Num FROM files GROUP BY categoryid

The problem is that if I run this query in phpmyadmin, I get a total of 4, which is right. But if I run this query within a php page, I only get 2 as a result.

Can anyone tell me why I get a different result?

Counting
for ($n=0;$n<1000;$n+50)
This does not seem to give a result of 0, 50, 100 for $n - it seems that when I use this for $n it goes 1,2,3,4 etc.

What is wrong with it?

Counting Rows
I need to get the number of rows in a table.

This is the query I'm using at the moment:

$query = "SELECT COUNT(*) from mytable";
$result = mysql_query($query) or die ...;

What php function may I use to get the number and in which way?

I tried with

$num = mysql_num_rows($result);

but nothing.

Counting Characters
Just a silly little problem i'm not entirely sure how to tackle. I'm wanting to search through a string for a certain character and then count the number of times it appears (or return false if it doesn't locate the character).

Counting An Array
i need to count 2-dimensional array $this->myarray[$a][$b] after $a, my code PHP Code:

Counting Matches
This is really more of a MySQL question than PHP per se, but the only
MySQL group my newserver carries seems to be pretty quiet, so I
thought I'd ask here.

What I am trying to do is determine the number of terms which match a
field in the database where an initial string of multiple words has
been broken up into single terms and the SQL statement is built by
looping through each term separately, something like this:

$original_string = "this is a test string"

// code to remove stop words/common terms leaves

$trimmed = "this test string"

// this is then exploded at the space into an array of its constituent
words. This array is then looped over to pass each word to an SQL
query thus

$SQL = "select * from main where"
while(there are terms){
$SQL .= "Title like '%" . $term . "%' OR"
}

// this would lead, using the above example, to an SQL query which
looks like this:

$SQL = "SELECT * FROM main WHERE Title like '%this%' OR Title like
'%test%' OR Title like '%string%'

What I need to do is to check how many of the terms actually match
something. Is there any way, either in MySQL or with the result array
in PHP, to determine this?

Counting Files In Dir ?
Is it possible to count the files in a certain server dir, and show the filenames ?

Click Counting
I have a links directory that I would like to count the number of times a link is clicked.

I currently have all the links being displayed by pulling the links data from a MySQL table. I have added the a 'Count' field to the existing table. The table contains the following fields: LinkID, Category, Name, URL, Description, Count.

My question is is it possible to count the clicks once the links data has been printed to HTML? I am thinking of the PHP equivalent of OnClick Count = Count + 1. Or have I got the whole logic back to front?

Counting Hits
I'm running a site with around 50k hits a day (hehe.. don't ask what kind of a site). What i want to do is this: Track the URL's on the site where a user clicks on, and I want to give some sites a URL where to sent hits to. Something like: http://www.domain.com/refer.php?site_x

Just this basic, so I can give every site it's own ID. What to do best for logging this or inserting this in the database? I can do something like checking for name: Code:

Counting Rows
I have an admin system (Add/Modify/Delete) for two types of records in the
database. They have a Parent - Child relationship

My problem is that I want to display on the "parent" record whether the
child exists or not .

The records are found in two different tables, but have the same Primary
Key.

Counting Traffic
Does enyone know of an approximate way of counting the traffic a script generates?

Counting Consective From Db
I have a table full of players with their number of points.  I want to rank them, but if they're are more than one I want to count those, and set a ranking to them.  For example:  let's say player A has 10pts, B 8pts, C 8pts, D 6pts, E 6pts, F 6pts, and G 2pts. Code:

Counting And Displaying Accordingly
I have a field in my database "number_photos" and lets say for example that number is 4. I want to make it so if # of photos = 4, it will display:

photo_0.jpg
photo_1.jpg
photo_2.jpp
photo_3.jpg

I was going to use foreach to do this, but it does not work / I don't think it is the correct way. So next I thought I would do:

$p = # of photos
$p++

To count up - but I need it to start at 0, and also need it to display the photo_0.jpg, etc.

Counting Query
I have a small online shop, i have 2 SQL tables, one called "orderlog" which stores each item the user has purchased and also a table called "ordertransactions" which store the master details of each order. Each row of the table "ordertransactions" has a unique ID number. An example is

<< orderlog >>

ID     ORDERID   TOTAL(£)
1      876          29.99
2      876          13.99
3      899          10.00

ID - this is a autoincreased number
ORDERID - this is the ID number for the master order details in the table `ordertransactions`
TOTAL - this is the total for each product bought

<< ordertransactions >>

ID     DATE
876   2007-08-12
899   2007-08-14

ID - this is a autoincreased number, this number is what is held in the field `ORDERID` in the `orderlog` table.
DATE - this is the date the order was placed, in the format YYYY-MM-DD.

As you can see, in the table `ordertransactions` there are 2 orders held, in the table `orderlog` you can see there are 3 rows, the first 2 rows relate to order ID 876 and the last row relates to order ID 899.

You will now notice that inside the table `ordertransactions` there is a date held in the format YYYY-MM-DD.

Okay, so what I want to do is to run a SUM query

SELECT SUM(price) FROM ***
on the `ordertransactions` table to return the total earned in a particular month. So if I run the query for the month August (08) then it would check the table `ordertransactions" for all rows where the month value equals 08, it would then grab the ID numbers for each of these rows and do a SUM on the `orderlog` table for all rows which contain those ORDER ID numbers, this would then return the TOTAL spent during the month 08. Does that make sense?

Counting In Tables
Well basically what i want to do is this:

I want to find an ammount of the same thing and echo it once but next to it have how many of that thing there are in a table.

So say i have 10 wooden swords i want it to echo the image of the sword once and show x10 next to it to show that it is in the database 10 times.

Counting Elements In A 2D Array
How can I count the number of items in a multidimensional array, this is what I am using but there must be a more efficent way
// contents is my 2D array
$len=count($contents);
if($len == 0)
echo "message";
else
{
// need to go thru and count our number of elements in the array
$counter = 1;
reset($contents);
while(next($contents))
$counter++;

Counting In A Flat File
Has anybody an idea, how I can count especially
some records (e.g. different category) in a flat file?

My script only counts the complete lines of the file

...
$count = 15;
$content = file($conf[myDataFile]);
$size = count($content);
...

I want to count each recorset that has the same
value (e.g. category) like the querystring ($cat)
Therefore I have to define the number of the field in the flat file.

...
($myLINES[$i][13]==$cat);
...

PHP/mySQL Counting Rows In My Db
I'm building a little news board and I need to count the total number of rows in my db ... simple, I know... but I can't get a result. here is the code...

Counting Query Matches
With this query:

SELECT * FROM tablename WHERE data='somedata'

What would I do to create a variable that would store the number of records the query matched?

Counting Numbers In Array
Assume I have an array which contains the following numbers:
2
5
7
9

How would I go about adding them to eachother?( e.g. in this case 2+5+7+9 would be 23)

Counting Records In A Table
Ok, I am trying to count the number of records in one of my tables. Seems simple. BUT! its not working. It returns a 2 no matter how many records are in there.

Heres the code.

<?php
$sql = "SELECT count(*) from cam";
$result = mysql_query($sql);
?>

I would think this would work.
I have also tried mysql_num_rows, and max(), and sum()...
a little help would be appreciated, and why is it returning a 2?

Counting Number Of Records
I am trying to do 2 things. First, i want to count all the records that i get when i query the db. Second i want run a loop to display all of the info.

The loop works fine, (it displays all the results) but when i try to count the records, it only echo's 1. Here is the code i'm using. PHP Code:

Problems Counting Queries
I am trying to count queries by calling $this->qcount++; after every successful query. But I can't get the qcount var to increase no matter how many times $db->query() is called. PHP Code:

Counting Downloads With PHP & MySQL
I have a PHP file that offers a file for download. What I want to do is update a MySQL table with the download event. Something like filename - date - time

I know how to update the data table but need to kick of the update routine from the <a Href...> link.

Counting Article Views
I have a news system on my site and would like to count how many times each article is viewed, how could I do this?

Counting In Dynamic Tables
I have a question that i think will be pretty easy for someone 'in the
know' to answer, but as of yet i have been unable to find anything on
google.

Basically, i have a page that is an overview of a shows reservations.
On it i have a dynamic table that shows all the nights in the system
for a particular show. I'd like one of the fields on each row of the
table to display the total of reservations made for that night. So each

row would display the total reservations (i.e. rows in the related
table) for the night it refers to, much like a message boards 'replies'

count.

Counting Characters In A String
I looked at the manual without luck, how do I count the characters in a variable? I just need the number of characters.

Counting Search Results
I would like to know if anyone can show me how to count search results in a MySQL database for a keyword ($keyword).

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.

Counting Search Result
I want to develop the result next/prev/1-10/11-20 etc thing.Say we have N records. We limit it to display M records at a time. So I have a question which is better, performance wise: Code:

Counting Survey Votes
Constructed a fairly big table with 20 rows, most of which are
TINYINTs based on user selection for a dropdown box. This is the form:

Each field obviously corresponds to a row in the table, and the
majority are integers indicating the user's selection.

My issue is how to do meaningful stuff with the stored data. I believe
I need to use GROUP BY functionality but I'm not certain - how can I
calculate, say, the number of "1" ('Excellent') values for the field
"writing_quality"?

Counting Nodes In A Tree
I have a simple tree structure where node x can have y children.
Node x's children are stored in an array.
I want to supply a node to a function and count the TOTAL number of
children for that node.
This is what I have come up with so far:

function count_total_children($tree)
{
$num_of_c = $tree->get_num_child();
echo $num_of_c.'+'
$child_array = $tree->get_child_arr();

for($i=0;$i<$num_of_c;++$i)
{
count_total_children($child_array[$]);
}
}

Now this clearly does not work but its the closest I've come. What
this bit of code does is if a node has 5 children it will output
something like:

1+2+0+0+2+

Rather than print out the number I need to add it to a running total,
but I just cant seem to do it!

Ive tried using references but it doesnt work when you do the
recursive call?

Counting Guest Sessions
I am wondering how i would go about counting guest sessions. is there a way to do it with out storing them in a database? I am just looking to get a number of how may ppl are using a part of my web site.

Counting Returned Mail
Im doing a newsletter system and I have to create a statistic page with the number of e-mail sent and returned. The e-mails sent is easy, but the returned mail i dont know how to do... Does any body know?

Counting Files In A Directory?
How could I account how many files there are in a directory and echo the amount?

Counting Unique Rows
I have a script that counts how many members have given good feedback for this person, but how do I specify how many unique members have given this person good feedback.  Meaining I don't want to count member1 2 times becuase he left feeback twice, I want to only count him once.


$total_num = mysql_result ( mysql_query("select count(*) as nr from feedback where rec ='".$_SESSION['id']."'") ,0,"nr" );

The above code is how I got the total number of feedbacks.

Counting How Many Dupliate Records
I have a field name "cname" and there are multiple records some are the same, some are not.

Example:
1. ebay
2. google
3. ebay
4. yahoo
5. ebay

How would I go about printing a list like this?
Ebay = 3
Google = 1
Yahoo =1

Iv'e tried the foreach function, but for some reason it is not valid. I know you can only use a foreach with an array, but I'm just learning arrays.

Counting Number Of Instances
I have a table surv_item and a field of "name"

in the name field, I would like to count the number of instances that name appear how would I go about in doing that?

Counting A Specific Id To Display
i have constructed a forum (very basic) i have 2 main categories , 1 has id 1 and the other 2.

once a topic is posted within these categories a 1 or a 2 is stored into `topic_id` which is in `forum_topics`

so if i post in category 1, a 1 is stored into `forum_topics` as a way of tracking the different categories that are added later, my problem is when i put my pagination in for the sections, (it displays the correct number of links for each section) but still shows me all the posts, the links are right but it still displays the posts on the 1 page Code:

Counting Records In MySQL
I've been trying to write a page that checks the database and counts the number of records and if the number is less than 3000, it loads page X, but if the number is equal to 3000, it loads page Y.

I know this should be a simple if/else statement but it's the checking and counting that I cannot get to work. 

Counting Image Views
I use this code to count how many times an image is viewed on the viewing page on my website:

$con = mysql_connect("?????","???????","????");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("???????", $con);

mysql_query("UPDATE files SET views = views+1 WHERE file_id = '$id'");
So that works of course. Although, there is a problem. When somebody uploads a file on my website, they are also given a direct link to the image/picture. If they post that image/picture somewhere else on the internet, the above code is obviously not executed, meaning the view count is innacurate.

How can I count how many times the image has been viewed including outside of my websites page? Is it possible to count how many times the image files has been requested from my server?

Counting Lines In A Flat File
I know that you can count the number of lines with PHP Code:

Php Counter Not Counting Unique Visitors HELP PLZ
<?php
include "config.php";
$date = date("Y-m-d");
$ip = $REMOTE_ADDR;
$query = "select * from count1 where ip='$ip'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num != "0") {
$query2 = "insert into count1 (ip) values ('$ip')";
$result = mysql_query($query2);
}else{
$query = "UPDATE count SET hits = hits+1 WHERE date='$date'";
$result = mysql_query($query);
}
?>

Its Updating the database but i want it to check the ip first so it checks it, And IFF it isnt In the db Already, add it into the dbIff it IS in the db, i dont want it to UPDATE!

Counting The Occurrence Of A Character In A String
I am just trying to count the number of occurrences of a character in a string e.g.

How many times does "a" appear in "Do you want an email notification of replies?"

Is there a PHP function that does this?

Counting Position Of Character In String
I am trying to calculate the postition(s) of a certain character in a string.
e.g (a binary string) ??', I want to calculate the &#391;' in the whole string and returning the charatersplace like &#393;|4|7', meaning that the 1 appears in the 3rd,4th and 7th position in the string.

Recursive Functions - Counting Calls
Is there an easy way to find out how many times a function has called itself? Or do you just count with a global variable?

Counting Items In An Array Having X Attribute
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned:

[connect]
$sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5";
$result = mysql_query($sql);
while($cards = mysql_fetch_array($result)) {

$value = $cards["card_value"];
$suit = $cards["card_suit"];
$image = $cards["card_image"];
--------

Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this:

$spades = 0;
if($suit='spades') {
$spades = $spades+1;
}

and I tried a foreach statement to count within the loop which always returns a count of 1.

Would someone be so kind as to point me in the right direction?

Counting The Number Of Records In Table
I want to count the number of records which apply to a repeating id field. (the user id remains the same, but their are several records which relate to the user. I want to know how many records in the table exist for a specified user id) Does anyone know a function for doing this?


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