2

I'm creating a table with data from two queries and tried to connect them in a table. Tried using something like this :

$counter = 1; 

    echo '<table border="0"  cellpadding="0" cellspacing="3"><tr>
                <td width="10%">Miejsce</td>
                <td width="25%">Nick</td>
                <td width="20%">SteamID</td>
                <td width="20%">Punkty</td>
                </tr>';

                    while($row = mysql_fetch_array($skill_b) AND $row2 = mysql_fetch_array($sid_b))
                    {
                      echo '<tr class="select">';
                      echo '<td>'.$counter.'</td>';
                      echo '<td><center>'.$row['lastName'].'</center></td>';
                      echo '<td><center>'.$row2['uniqueId'].'</center></td>'; 
                      echo '<td><center>'.$row['skill'].'</center></td>';
                      echo '</tr>
                    $counter++; 
                    } 

    echo '</table>';

and

$counter = 1; 
    echo '<table border="0"  cellpadding="0" cellspacing="3"><tr>
                <td width="10%">Miejsce</td>
                <td width="25%">Nick</td>
                <td width="20%">SteamID</td>
                <td width="20%">Punkty</td>
                </tr>';
                                          echo '<tr class="select">';
                                          echo '<td>'.$counter.'</td>';
                    while($row = mysql_fetch_array($skill_b))
                    {
                      echo '<td>'.$row['lastName'].'</td>';
                    } 
                    while($row2 = mysql_fetch_array($sid_b))
                    {
                      echo '<td>'.$row2['uniqueId'].'</td>'; 
                    } 
                    while($row3 = mysql_fetch_array($skill_b))
                    {
                      echo '<td>'.$row3['skill'].'</td>';
                    } 
                    $counter++; 
    echo '</table>';

The second one almost works, although it crashes the whole table, so I can't see all the results.

Query looks like this if there's something that can be changed in them:

   $query_skill = sprintf(
  "SELECT skill, lastName
  From hlstats_Players
  ORDER BY skill DESC
  LIMIT 10");

$skill_b = mysql_query($query_skill);
$skill = mysql_result( $skill_b, -1 );

$query_sid = sprintf(
  "SELECT uniqueId
  From hlstats_PlayerUniqueIds
  WHERE playerId='$pid_b'"
  );

$sid_b = mysql_query($query_sid);
$sid = mysql_result( $sid_b, 0 );

2 Answers 2

1

Your first attempt is almost right. The only problem is the operator precedence.

Try this:

while(($row = mysql_fetch_array($skill_b)) && ($row2 = mysql_fetch_array($sid_b)))

That said, you should probably restructure your query using a JOIN, but I can't give any additional help there without seeing your current queries. See edit below.

Also, note that <center> is deprecated in favour of CSS. In this case:

<td style="text-align:center">

EDIT: Try this query:

SELECT a.skill, a.lastName, b.uniqueId
FROM hlstats_Players a
JOIN jlstats_PlayerUniqueIds b ON a.id = b.playerId
LIMIT 10
Sign up to request clarification or add additional context in comments.

Comments

0

try this this works fine for me

<?php
mysql_connect('localhost','root','');
mysql_select_db('your_db');
$counter = 1; 
    echo '<table border="0" style="text-align:center;" cellpadding="0" cellspacing="3"><tr>
                <td width="10%">Miejsce</td>
                <td width="25%">Nick</td>
                <td width="20%">SteamID</td>
                <td width="20%">Punkty</td>
                </tr>';

$skill_b = mysql_query('select * from table_name limit 10');
$sid_b = mysql_query('select * from table_name limit 10');

                    while($row = mysql_fetch_array($skill_b) AND $row2 = mysql_fetch_array($sid_b))
                    {
                      echo '<tr class="select">';
                      echo '<td>'.$counter.'</td>';
                      echo '<td><center>'.$row['colu_name'].'</center></td>';
                      echo '<td><center>'.$row2['colu_name'].'</center></td>'; 
                      echo '<td><center>'.$row['colu_name'].'</center></td>';
                      echo '</tr>';
                    $counter++; 
                    } 

    echo '</table>';
    ?>

please comment if something goes wrong, if any mistake please mention it

Thank you

1 Comment

just add the query as you wish at the line 12 and 13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.