[PHP/MySQL]Live Score Board

OK i created the table with fake data laid out like the diagram…

[php]

Scoreboard Table
  <table id="left-overall-header" width="100%" border="0">
    <tr>
      <td>&nbsp;</td>
      <td><div align="center"> 
          <!-- Start Left Side Team -->
          <table id="left-team" width="100%" border="1">
            <tr>
              <th><div align="center">US</div></th>
            </tr>
          </table>
          <!-- End Left Side Team --> 
        </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><div align="center"> 
          <!-- Start Left Side Data Headers -->
          <table id="left-DataHeaders" width="100%" border="1">
            <tr>
              <th><div align="center">Player</div></th>
              <th><div align="center">Squad</div></th>
              <th><div align="center">K/D</div></th>
              <th><div align="center">Score</div></th>
            </tr>
          </table>
          <!-- End Left Side Data Headers --> 
        </div></td>
    </tr>
  </table>
  <br />
  
  <!-- Start Left Side Data -->
  
  <table id="left-data" width="100%" border="1">
    <tr>
      <td><div align="center"><a href="#">Adam</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">Adam</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">Adam</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">Adam</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">Adam</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
  </table>
  
  <!-- End Left Side Data --></td>
<!-- End Left Side --> 
<!-- Start Break between left/right -->
<td></td>
<!-- End Break between left/right -->
<td><!-- Start Right Side -->
  
  <table id="Right-overall-header" width="100%" border="0">
    <tr>
      <td>&nbsp;</td>
      <td><div align="center"> 
          <!-- Start Right Side Team -->
          <table id="right-team" width="100%" border="1">
            <tr>
              <th><div align="center">RU</div></th>
            </tr>
          </table>
          <!-- End Right Side Team --> 
        </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><div align="center"> 
          <!-- Start Right Side Data Headers -->
          <table id="Right-DataHeaders" width="100%" border="1">
            <tr>
              <th><div align="center">Player</div></th>
              <th><div align="center">Squad</div></th>
              <th><div align="center">K/D</div></th>
              <th><div align="center">Score</div></th>
              <th><div align="center">Stats</div></th>
            </tr>
          </table>
          <!-- End Right Side Data Headers --> 
        </div></td>
    </tr>
  </table>
  <br />
  
  <!-- Start Right Side Data -->
  
  <table id="right-data" width="100%" border="1">
    <tr>
      <td><div align="center"><a href="#">John</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">John</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">John</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">John</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
    <tr>
      <td><div align="center"><a href="#">John</a></div></td>
      <td><div align="center">Alpha</div></td>
      <td><div align="center">25/2</div></td>
      <td><div align="center">1100</div></td>
    </tr>
  </table>
  
  <!-- End right Side Data --></td>
<!-- End right Side --> 
[/php]

so using my code or some variation of my code how would i get it to display properly?

[php]<?php
$con=mysqli_connect(“host”,“user”,“pass”,“dbname”);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$query = ‘SELECT
cp.Soldiername,
cp.Kills,
cp.Deaths,
cp.Score,
s.squadName,
t.teamName
FROM
tbl_currentplayers AS cp
LEFT JOIN tbl_teams AS t ON t.teamID = cp.TeamID
LEFT JOIN tbl_squads AS s ON s.squadID = cp.SquadID
ORDER BY
t.teamID ASC,
s.squadName ASC’;

$result = mysqli_query($con,$query);
$num_rows = $result->num_rows;
if($num_rows > 0) {
echo “<table class=“onlinePlayers”>

<TH colspan=“2”>US<TH colspan=“2”>RU Squad K/D Squad K/D ”;
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC);){
echo “”;
echo “<a href=“https://i-stats.net/index.php?action=pcheck&player=” . $row[‘Soldiername’] . “&game=BF3&sub=Check+Player” target=_blank>” . $row[‘Soldiername’] . “”;
echo “” . $row[‘teamName’] . “”;
echo “” . $row[‘squadName’] . “”;
echo “” . $row[‘Kills’] . “/” . $row[‘Deaths’] . “”;
echo “”;
}
}else {
echo “<table class=“onlinePlayers”>”;
echo “<td colspan=“5”>No Players Online” ;
}
echo “<td colspan=“5”><a class=“button” href=”#" target="_blank">Play Now!" ;
echo “”;
mysqli_close($con);
?> [/php]

Well, the simplest way is to create two queries. One for the US and one for RU. Just use the where clause and
select just the data for US and RU instead of lumping them all together. Then, in your posted code, you would
replace lines 48-77 with a loop to display the US names. You would loop thru the soldiers in that list using your
WHILE clause and display a line for each row. (

data… etc… ) And, then do the same
for the RU table. Since you already have it laid out, the table I mean, then all you need is to replace the rows in
each of the two tables for with the live data.

Now, you can do it with just one query if you wish, and create two WHILE loops to create the rows, but, you
would need to check for the team (US/RU) inside the loop. Either way would work. Perhaps it might be easier
to use just one query and the same code for each table.

Give it a try and let us know if it works or fails. And, post the code either way in case we can help you improve
it at all…

ok here is my attempt at joining the table design with the php/mysql code … WARNING its ugly and probably not the most efficient way of doing it LOL. It works but the table design gets thrown off as you can see HERE … I really suck at tables and getting them adjusted right, how can i fix the layout so that the headers and data cells line up?

[php]

”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
} ?>
 
US
 
Player
Squad
K/D
Score

<?php $con=mysqli_connect("host","user","pass","dbn"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }

$query = ‘SELECT
cp.Soldiername,
cp.Kills,
cp.Deaths,
s.squadName,
t.teamName,
cp.Score
FROM
tbl_currentplayers_test AS cp
LEFT JOIN tbl_teams AS t ON t.teamID = cp.TeamID
LEFT JOIN tbl_squads AS s ON s.squadID = cp.SquadID
WHERE
cp.TeamID = 1
ORDER BY
t.teamID ASC,
s.squadID ASC’;

$query2 = 'SELECT

cp.Soldiername,
cp.Kills,
cp.Deaths,
s.squadName,
t.teamName,
cp.Score
FROM
tbl_currentplayers_test AS cp
LEFT JOIN tbl_teams AS t ON t.teamID = cp.TeamID
LEFT JOIN tbl_squads AS s ON s.squadID = cp.SquadID
WHERE
cp.TeamID = 2
ORDER BY
t.teamID ASC,
s.squadID ASC’;

$result = mysqli_query($con,$query);
while($row = mysqli_fetch_assoc($result)){
echo “

”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
} ?>
<div align=“center”><a href=”#">" . $row[‘Soldiername’] . “<div align=“center”>” . $row[‘squadName’] . “<div align=“center”>” . $row[‘Kills’] . “/” . $row[‘Deaths’] . “<div align=“center”>” . $row[‘Score’] . “
    <!-- End Left Side Data --></td>
  <!-- End Left Side --> 
  <!-- Start Break between left/right -->
  <td></td>
  <!-- End Break between left/right -->
  <td><!-- Start Right Side -->
    
    <table id="Right-overall-header" width="100%" border="0">
      <tr>
        <td>&nbsp;</td>
        <td><div align="center"> 
            <!-- Start Right Side Team -->
            <table id="right-team" width="100%" border="1">
              <tr>
                <th><div align="center">RU</div></th>
              </tr>
            </table>
            <!-- End Right Side Team --> 
          </div></td>
        <td>&nbsp;</td>
     </tr>
     <tr>
       <td colspan="3"><div align="center"> 
           <!-- Start Right Side Data Headers -->
           <table id="Right-DataHeaders" width="100%" border="1">
             <tr>
               <th><div align="center">Player</div></th>
               <th><div align="center">Squad</div></th>
               <th><div align="center">K/D</div></th>
               <th><div align="center">Score</div></th>
               <th><div align="center">Stats</div></th>
             </tr>
           </table>
           <!-- End Right Side Data Headers --> 
         </div></td>
     </tr>
   </table>
   <br />
   
   <!-- Start Right Side Data -->
   
   <table id="right-data" width="100%" border="1">
   <?php
     $result2 = mysqli_query($con,$query2);

while($row = mysqli_fetch_assoc($result2)){
echo “

<div align=“center”><a href=”#">" . $row[‘Soldiername’] . “<div align=“center”>” . $row[‘squadName’] . “<div align=“center”>” . $row[‘Kills’] . “/” . $row[‘Deaths’] . “<div align=“center”>” . $row[‘Score’] . “
   <!-- End right Side Data --></td>
 <!-- End right Side --> 
<?php mysqli_close($con); ?> [/php]

I am not seeing the issue, the table looks like you want it to. Other that the cells not being populated, what is the issue with how it looks?

LOL, you are getting there! But, there is no ALIGN tag inside of DIV’s. You need to use STYLE instead.
You should use it like this…

...

i added some false data to the table just to populate it …

i will make the div changes now

EDIT::
[member=43746]ErnieAlex[/member]
Ok the div’s are fixed as you stated

[member=72272]astonecipher[/member]
if you look at the tables the RU side is wider than the US side and the actual data is mis-aligned with the headers

Oh, also, when you have a row in a table and you want it to be the width of the table and cover all of the cells,
you can do it like this:

US ( To span across four cols... )

But, also, why did you place all those nested tables into the code? Silly… You only need one table and two
rows. Then, add the rows of data… Loosely, something like this:

US
Player Squad K/D Score
Ernie KillerSquad 3234/3113 1000234
So much neater than yours... You will have to code the last row with your queries and of course add in your styling for how it looks... Styling will make them stand out however you want them. Just a sample...

i nested the tables because it achieved the layout that i wanted … i wanted a border around US but i also wanted the cell US is located in to be slightly smaller than the data header table to give it that stacked look… Is there a better way to achieve that look? Im trying to not get it looking generic … i like the step down look, it makes it more appealing to the eye (IMHO)

It is ALWAYS best to make it look like you want it too… If you used CSS and DIV’s instead of a table, you
can make it very fancy looking… Lots of samples around…

But, using DIV’s with CSS, you can create some really nice displays. Here is a sample. Just put it into a new
file and look what it does. Not much code. You could turn your square design into a fancy one with little work.

[php]

SECTION ONE
SECTION TWO
[/php] Just an idea....

well its starting to look like i have bitten alot more off than my skill is able to chew on so i think i am going to leave it as it is. I doubt that i am going to be able to get it todo what i want without hiring someone to do it for me so i guess i will have to revisit it once i have learned alot more. Thank you all for your help. i really appreciate all the time and effort that you guys put into these forums.

Sponsor our Newsletter | Privacy Policy | Terms of Service