[UNsolved] mySQL query code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

[UNsolved] mySQL query code

Post by bla5e »

Code: Select all

echo $data["calwins"];
					  echo (" - ");
					  echo $data["calloss"];
					  echo (" - ");
					  echo $data["caltie"];
					  echo ("<br><br><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>U</b>nited <b>G</b>aming <b>S</b>yndicate (UGS):");
					  echo $data["ugswins"];
					  echo (" - ");
					  echo $data["ugsloss"];
					  echo (" - ");
					  echo $data["ugstie"];					  
					  echo ("<br><br><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">Overall:");
					  echo $data["overallwins"];
					  echo (" - ");
					  echo $data["overallloss"];
					  echo (" - ");
					  echo $data["overalltie"];
how do i get cal<fill in> and ugs<fill in> to add up to overall<fill in>?

whats the code?


-- also --

whats the code so it only list's 1 set of numbers, not even win/loss/tie submitted (ex: right now i have

Code: Select all

while ($data = mysql_fetch_assoc($result)) {
)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Code: Select all

$calwins += $new_calwins
Maybe share a little more on what you're trying to do and what you need help with :)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

pickle wrote:

Code: Select all

$calwins += $new_calwins
Maybe share a little more on what you're trying to do and what you need help with :)
its for clan, i want the CAL score and UGS Score to add together to get the Overall Score
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

pretty simple I think:

Code: Select all

$overall_score =($calwins - $calloss) + ($usgwins - $usgloss)
Last edited by pickle on Mon Jul 19, 2004 4:04 pm, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe something like this?

Code: Select all

<?php

$prefixes = array('cal','ugs');
$parts = array('wins','loss','tie');

foreach($parts as $part)
{
  if(isset($data[$prefixes[0].$part]) && isset($data[$prefixes[1].$part])
    $data['overall'.$part] = (int)$data[$prefixes[0].$part] + (int)$data[$prefixes[1].$part];
}

?>
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

pickle wrote:pretty simple I think:

Code: Select all

$overall_score =($calwins - $calloss) + ($usgwins - $usgloss)
not really what i ment.. but u gave me an idea

Code: Select all

$overall_wins = ($calwins + $ugswins)
$overall_loss = ($calloss + $ugsloss)
$overall_tie = ($caltie + ugstie)
that would work successfully wouldnt it?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Yep.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

whats the code so it doesnt echo every line in the mySQL table?

(what i have right now:

Code: Select all

while ($data = mysql_fetch_assoc($result)) { echo $data["calwins"];
)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

can you rephrase your question a bit better?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Code: Select all

$data = mysql_fetch_assoc($result))
keeps making each data with in a table echo out to a page..

example: echo $data["test"];

each item that lies under "test" feild is outputted.. i just want 1 output
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you should structure your query such that it returns the row(s) you want then.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

feyd wrote:you should structure your query such that it returns the row(s) you want then.
something like

Code: Select all

<?php

mysql_query("SELECT * FROM `records` LIMIT 1");

?>
or

Code: Select all

<?php

mysql_query("SELECT * FROM `records` WHERE id='".$_GET["id"]."'");

?>
which will find a certain record depending on which var is in the url
ie. index.php?id=5
Post Reply