Jump to content

Want to call up results from one query, run a math script against that...


AnAmericanGunner

Recommended Posts

I don't even know how to explain what I want to do as a subject. >.<

 

Okay, so what I want to do is pull up all the entries in a table, (in this case "horse") for a specific location. Then, I want to pull all the results for that horse from the "result" table. Next, I want to compare each result from that table to a list of if/elseif for points. Finally, I want all the points gathered and totaled and displayed for that horse, and every other horse at that location, in a single page.

 

Here is the coding that I have:

 

<?
---- connection information is here but removed -----


echo "<table>
<tr><td><b>Name</b></td> <td><b>Points</b></td> <td><b>Title</b></td></tr>";

//finds horses at specific location
$query = "SELECT * FROM horse WHERE location='DESIRED_LOCATION' ORDER BY name";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];

        //gathers results based upon the above two pieces of information
        //the include is shown below as it contains the point info
include('includes/points.php'); 
$query92 = "SELECT * FROM results WHERE MAIN_KEY='$id' OR MAIN_KEY = '$name'";
$result92 = mysql_query($query92) or die (mysql_error());
while($row92 = mysql_fetch_array($result92)) {
$place = $row92['place'];
echo "<tr><td>$name</td> <td>$points</td> <td>$title</td></tr>";
}
}
echo "</table>";
?>

 

and this is the points.php file:

<? 

if($place === '1st') {$points += 50;}
elseif($place === '2nd') {$points += 45;}
elseif($place === '3rd') {$points += 40;}
elseif($place === '4th') {$points += 35;}
elseif($place === '5th') {$points += 30;}
elseif($place === '6th') {$points += 25;}
elseif($place === '7th') {$points += 20;}
elseif($place === '8th') {$points += 15;}
elseif($place === '9th') {$points += 10;}
elseif($place === '10th') {$points += 10;}
elseif($place === 'CH') {$points += 50;}
elseif($place === 'RCH') {$points += 40;}
elseif($place === 'TT') {$points += 30;}
elseif($place === 'T5') {$points += 30;} 

if($points < 500) {$title = "No Title";}
elseif ($points >= 500 && $points < 1000) {$title = "Champion";}
elseif ($points >= 1000 && $points < 2500) {$title = "Grand Champion";}
elseif ($points >= 2500 && $points < 5000) {$title = "State Champion";}
elseif ($points >= 5000 && $points < 8000) {$title = "National Champion";}
elseif ($points >= 8000 && $points < 10000) {$title = "World Champion";}
elseif ($points >= 10000) {$title = "Hall of Fame";}
?>

Unless I'm overlooking something major, it's doing nearly the same thing; totaling a value based on a corresponding value, no? If not, what specifically is giving you problems with this script?

I want a script that runs a query and pulls all horses from a table ("horse") from a specific location ("DESIRED_LOCATION"). That script runs fine.

Next, there's another query that takes the horse's main key and name and searches a second table ("results") for any records matching that name or main key. Then it compares the place to the values on the points file and echoes the results.

 

Except it doesn't do it right when there's more than one horse being pulled up.

 

But don't worry. Someone who actually knows what I want done is working on it for me.

And you still haven't explained the problem. "It doesn't do it right" is pretty useless without a description of what is expected versus what actually happens. The only information we have is what you post. Nobody here is looking over your shoulder and sees what you see on your monitor, so a poor explanation will nearly always lead to inaccurate answers.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.