473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP/MySQL... I need to add up multiple rows!

I got this wrestling database I'm developing. It's not as straight and narrow as most sport databases are, but this has got me stumped a bit. I am trying to implement their stats in to their specific profiles, but instead of having them naturally split (while loop), I need them to be accumulated (sp?) in to win one sole row of data. So in essence, I want all of the possible values added as one complete value. I'm going to give some rough examples below:

profiles (db)
=========
$bio_id (auto_increment)

$bio_id
=====
Wrestler 1 ($bio_id =1)
Wrestler 2 ($bio_id=10)
Wrestler 3 ($bio_id=24)
Wrestler 4 ($bio_id=47)


shows (db)
========
$segment_id (auto_increment)
$record01 ($record01=$bio_id)

$bio_id vs. $bio_id = $record01
=======================
1 v 10 = 1
24 v 1 = 24
10 v 47 v 1 = 1

So we have three matches inserted. I can get those showing up fine and dandy and even in the correct profiles. The trick is to have it give me a total of Matches, Wins, and Losses. With the "while" loop, I can get each separate match records displayed (only three would logically show here). When I display the data without the "while" loop, I only get 1 row (the other 2 rows are ignored). What I want are totals like the examples below:

Wrestler 1 (1)
M / W - L
==========
3 / 2 - 1

Wrestler 2 (10)
M / W - L
===========
2 / 0 - 2

Wrestler 3 (24)
M / W - L
===========
1 / 1 - 0

Wrestler 4 (47)
M / W - L
===========
1 / 0 - 1

The unique (to each profile) match results weren't too bad, because I am using the "while" loop statement to display them, but having all 3 rows (matches) of data be accumulated (sp?) for the stats part is a thinker for me. I tried doing this two ways, what you see here and I also attempted using separated records (record01, record02, record03...) where I designated "1" as win and designated "0" as loss.

This problem could be a database structuring problem in MySQL and/or possibly a coding problem in PHP. So note that I can get the data to show in each profile, but either I display using the "while" loop and get 3 rows displaying or I get only the newest row (or whatever row I GROUP BY) displaying only the top most row.

Let me know if I confused you in anyway or if you need more information as I would be happy to supply it. Thanks in advance for any help and/or advice on this issue.

Adding this may help somewhat:
[PHP]$shows_query = "SELECT (record01 = '$bios[bio_id]') AS win, (record01 != '$bios[bio_id]') AS loss
FROM shows
WHERE wrestler01 = '$bios[bio_id]' OR wrestler02 = '$bios[bio_id]'
OR wrestler03 = '$bios[bio_id]' OR wrestler04 = '$bios[bio_id]'
GROUP BY match_id DESC";
$shows_query_result = mysql_query($shows_query);
$shows = mysql_fetch_array ($shows_query_result);

$win = $shows['win'];
$loss = $shows['loss'];
$total = $win + $loss;

echo "<br />$total - $win - $loss<br /><br />";[/PHP]
Mar 18 '07 #1
0 1654

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: phpfrizzle | last post by:
Hi there, I have a site with products on it. The site has a mysql backend. All products belong to certain series (table series). There can be up to 4 different products (table products)...
7
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
6
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm raid 5 on u320 perc raid...
9
by: elyob | last post by:
Hi, I'm looking at storing snippets of details in MySQL about what credit cards a business excepts. Rather than have a whole column for Visa, another for Amex etc ... I am looking at having a...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
1
by: mpar612 | last post by:
Hi everyone, I'm not sure if this is asking too much or not. I am trying to get the following PHP code to work on my website. It utilizes PHP 5, MySQL 4.1 and the PEAR DB module. I am...
2
by: julie18881 | last post by:
I may be being really stupid here, i have spent the last 3 hours looking round your site and some other for answers to my problem, but have not had much luck (possibly cuase my brain just isn't...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.