473,819 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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_re sult = mysql_query($sh ows_query);
$shows = mysql_fetch_arr ay ($shows_query_r esult);

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

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

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

Similar topics

23
2568
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) (categories 1-4) in 1 series. Each product has a defined 'series ID' which tells us
7
5663
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 students on the screen at the same time, modify some, mark some for deletion and even have blank fields at the end to add a new record. In HTML which is generated I label each row and input field with a name/number combination i.e <input type=text...
0
3536
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 form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
0
3954
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
6
22542
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 cards, dell 2600/4600's with single channel backplanes (new ones will have dual channel) All have 2 gig of ram, but I've never seen mysql use more than 300mb of ram.
9
1881
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 column called payment types and inserting multiple codes ... e.g. ViAmBcCa Is this a good way of doing things? To me it'd be a lot cleaner and limit amount of Db work to be done. Is this a sensible way in your opinion? What's the best way of...
9
2802
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 this: id Name Surname pictr0 picrt1 pictr2 pictr3
1
3376
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 having issues retrieving data from the form. It won't retrieve all of the data only a part of it. All of the code is below and I also attached the code for the main file. I seem to understand everything except for the last 40 or so lines of code,...
2
2649
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 working today) I have EasyPHP2.0b1 Apache/MySQL server installed on my Windows XP(SP2) machine. This runs Apache 2.2.3, MySQL 5.0.27 and PHP 5.2.0 I have a PHP code filled listbox, which allows multiple selections. Actual Values are "rcd_no, cn_no"...
6
38534
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 through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
0
10704
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10458
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10159
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6910
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5590
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5724
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3046
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.