Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-23-2005, 10:42 AM Counting data?
Experienced Talker

Posts: 35
Trades: 0
Hi Guys,

I have a table in mysql database called appearances, with an example below of the structure with the variable name at the top



Now as you can see each of the surnames have been saved into a record in the database.

Now what I want to do is create a php piece of code which looks in all the variable names and counts how many times harvey for example has been entered into the database. So it would look through all the variables and nomatter what $shirt variable they are in it will see:

Harvey = 3

and that is incremented every time a new record is added with Harvey in it?

Any ideas please?

Thanks

Chris
chrisb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2005, 12:49 PM
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
How about a while loop running through the rows of data and an if statement checking the values of the variables and incrementing a variable if it's right. Maybe something like below?


PHP Code:

$test_name 
"harvey";
$name_count 0;

include(
'config.php');

$result mysql_query("SELCT * FROM appearances");

while (
$result_array mysql_fetch_array($result)) {

$shirtone $result_array['shirtone'];
$shirttwo $result_array['shirttwo'];
$shirtthree $result_array['shirtthree'];

if(
$shirtone == $test_name) {
     
$name_count++;
}

if(
$shirttwo == $testname) {
     
$name_count++;
}

if(
$shirtthree == $testname) {
     
$name_count++;
}

}

print 
$test_name " appears " $name_count " times."
Hopefully that works and actually comes close to solving the problem......

Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Counting data?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09623 seconds with 12 queries