Jump to content

Calling array values.


tomz0r

Recommended Posts

Hello,

 

I am having some trouble with calling certain array values while a condition equals something.

 

I have called values from a database table into an array:

 

$result = mysql_query("SELECT `TeamID`, `ScoreA`, `ScoreB`,`TeamPlayed`, `RoundNum` FROM `scores` WHERE `CompID` = 4 ORDER BY `RoundNum` ASC") or die(mysql_error());

while($row = mysql_fetch_assoc($result))
{
print_r($row);
}

 

Array
(
    [TeamID] => 3
    [scoreA] => 16
    [scoreB] => 4
    [TeamPlayed] => 4
    [RoundNum] => 1
)
Array
(
    [TeamID] => 1
    [scoreA] => 16
    [scoreB] => 1
    [TeamPlayed] => 6
    [RoundNum] => 1
)
Array
(
    [TeamID] => 2
    [scoreA] => 16
    [scoreB] => 14
    [TeamPlayed] => 5
    [RoundNum] => 1
)
Array
(
    [TeamID] => 4
    [scoreA] => 16
    [scoreB] => 0
    [TeamPlayed] => 6
    [RoundNum] => 2
)
Array
(
    [TeamID] => 1
    [scoreA] => 10
    [scoreB] => 16
    [TeamPlayed] => 2
    [RoundNum] => 2
)
Array
(
    [TeamID] => 5
    [scoreA] => 14
    [scoreB] => 16
    [TeamPlayed] => 3
    [RoundNum] => 2
)

 

From here I want to able to get display certain values while RoundNum = $value

 

So while RoundNum = 1

display the array values of:

TeamID V TeamPlayed
ScoreA  -  ScoreB

 

Hope you can decipher what I am asking, don't think I have worded it very well :S.

Thanks for anyhelp!

 

Link to comment
https://forums.phpfreaks.com/topic/213124-calling-array-values/
Share on other sites

replace

print_r($row);

 

With:

if($row['RoundNum'] == 1) {
echo '<table><tr><td>' . $row['TeamID'] . '</td><td> VS </td><td>' . $row['TeamPlayed'] . "</td></tr>\n"
         .'<tr><td>' . $row['ScoreA'] . '</td><td> </td><td>' . $row['ScoreB'] . "</td></tr>\n</table>";
}

       

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.