Jump to content

[SOLVED] PHP Problem


Dane

Recommended Posts

Hi guys.

 

I have a table which looks like: Below:

table.jpg

 

What i need to do is extract those results from the database so that the results are shown below.

 

Team 1  D D W L L

Team 2  D D L W W

 

I have this peice of code that i have done but its not working correctly.

 

<?php

$winimage = "<img src=\"images/win.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">";
$drawimage = "<img src=\"images/draw.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">";
$loseimage = "<img src=\"images/lose.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">";

$lresultsQuery = "SELECT * FROM `ladder_results` WHERE `result_teamid` && `result_vsteamid` = '$ladder_teamid' ORDER BY `result_date` ASC";
$lresultsresult = mysql_query($lresultsQuery, $connect) or die(mysql_error());

while ($resultr = mysql_fetch_array($lresultsresult))

{

$result_rid = $resultr['result_rid'];
$result_date = $resultr['result_date'];
$result_teamid = $resultr['result_teamid'];
$result_vsteamid = $resultr['result_vsteamid'];
$result_for = $resultr['result_for'];
$result_against = $resultr['result_against'];
$result_rmap = $resultr['result_map'];

// Statments To Use Correct Image For Win, Lose or Draw
if ($result_for > 15 || $result_for == 1 || $result_for == 0)

{ echo $winimage; }

else if ($result_for < 15)

{ echo $loseimage; }

else if ($result_for == 15)

{ echo $drawimage; }

}

?>

 

That code extracts 5 results from the database.

 

Team 2  D W L

Team 1 D W

 

Any ideas on how to get this working correctly?

 

Thanks guys

Link to comment
Share on other sites

$lresultsQuery = "SELECT * FROM `ladder_results` WHERE `result_teamid` = '$ladder_team_id' OR `result_vsteamid` = '$ladder_team_id' ORDER BY `result_date` ASC";

 

Give that a try, see if that fixes it, I have a feeling the one you have at the minute is only pulling it if it matches the first team, not if it is the vs team.

 

I dry-ran your code in my head and it behanves as i would expect, give my sql a try see what happens. Dependant on the rest of the code, you might need to swap variables around if it matches the first or the last team in the db. Sorry that sounds confusing, but when you try my sql you might find it shows results the incorrect way around

 

Adam

Link to comment
Share on other sites

Hi

 

That query is pulling the results as such..

 

Team 2 -  D D W W L

Team 1 -  D D W W L

 

The whole peice of code is

 

<?php

require_once('settings.php');


?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="10%" valign="middle">Position</td>
<td width="20%" valign="middle">Points</td>
<td width="50%" valign="middle">Team Name</td>
<td width="20%" valign="middle">Form</td>
<td width="10%" valign="middle">Challenge</td>
</tr>
<?php

// Get Teams In Ladder
$ladderQuery = "SELECT * FROM `ladder` WHERE `ladder_lid` > '0' ORDER BY `ladder_points` DESC";
$result = mysql_query($ladderQuery, $connect) or die(mysql_error());

$position = 1;

while ($ladderc = mysql_fetch_array($result))

{

$ladder_lid = $ladderc['ladder_lid'];
$ladder_teamid = $ladderc['ladder_teamid'];
$ladder_points = $ladderc['ladder_points'];

// Get The Team Name
$teamnameQuery = "SELECT * FROM `teams` WHERE `team_tid` = $ladder_teamid";
$nameresult = mysql_query($teamnameQuery, $connect) or die(mysql_error());

while ($teamname = mysql_fetch_array($nameresult))

{

$team_tid = $teamname['team_tid'];
$team_name = $teamname['team_name'];

} // End Get The Team Name Query

?>
<tr>
<td width="10%" valign="middle"><?php echo $position ?></td>
<td width="20%" valign="middle"><?php echo $ladder_points ?></td>
<td width="50%" valign="middle"><?php echo $team_name ?></td>
<td width="20%" valign="middle">

<?php 

$winimage = "<img src=\"images/win.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">";
$drawimage = "<img src=\"images/draw.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">";
$loseimage = "<img src=\"images/lose.gif\" width=\"13\" height=\"12\"><img src=\"images/spacer.gif\" width=\"1\">";

$lresultsQuery = "SELECT * FROM `ladder_results` WHERE `result_teamid` = '$ladder_teamid' OR `result_vsteamid` = '$ladder_teamid' ORDER BY `result_date` ASC";

$lresultsresult = mysql_query($lresultsQuery, $connect) or die(mysql_error());

while ($resultr = mysql_fetch_array($lresultsresult))

{

$result_rid = $resultr['result_rid'];
$result_date = $resultr['result_date'];
$result_teamid = $resultr['result_teamid'];
$result_vsteamid = $resultr['result_vsteamid'];
$result_for = $resultr['result_for'];
$result_against = $resultr['result_against'];
$result_rmap = $resultr['result_map'];

// Statments To Use Correct Image For Win, Lose or Draw
if ($result_for > 15 || $result_for == 1 || $result_for == 0)

{ echo $winimage; }

else if ($result_for < 15)

{ echo $loseimage; }

else if ($result_for == 15)

{ echo $drawimage; }

}

?>

</td>
<td width="10%" valign="middle">Yes</td>
</tr>
<?php

$position++;

} // End Teams In Ladder Query

?>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="100%" valign="middle" align="right">
<select size=1 name="game">
<?
$gameQuery=mysql_query("SELECT * FROM `ladder_games` WHERE `active`='1' ORDER BY `name` ASC");

while($gi=mysql_fetch_array($gameQuery))

{

if($gi['id']==$i['game'])

{

$sel="selected";

}

else

{

$sel="";

}

echo "<option value=\"".$gi['id']."\" $sel>".stripslashes($gi['name'])."</option>";

}

?>
</select>
</td>
</tr>
</table>

Link to comment
Share on other sites

I took the liberty of pastebin'ing the code for some syntax highlighting and a changelog

 

http://pastebin.com/pastebin.php?diff=d6a44acae

 

I added 5 lines in there (around line 71), by adding that code see what happens. (it is the code i meant when i said about swapping variables. I didnt check the $temp wasn't already in use so maybe you need to change the variable name

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.