0

I have a table that I am displaying a users current attack lvl and username in. In that table I also have have two columns that I want to display players exp and players rank.

The problem I am having is the players experience is in a different table and I don't know how to make another array to pull the players experience based on the username pulled from the first array. And also the rank can be achieved with the first array but I don't know how to make it display a ascending numeral for each loop.

<table  align="center">
<tr>
<th colspan="4"><font color="#d3d3d3">Attack Leaders</th>
</tr>

<tr>
<th width="100"><font color="#d3d3d3">Rank</th>
<th width="100"><font color="#d3d3d3">Username</th>
<th width="100"><font color="#d3d3d3">Experience</th>
<th width="100"><font color="#d3d3d3">Level </th>
</tr>

<?php

$sql = "SELECT user, cur_attack FROM curstats order by cur_attack desc LIMIT 25";
$result = mysql_query($sql) or die(mysql_error());

$user = $cut_attack = array();
while($row = mysql_fetch_assoc($result)) {
$user[] = $row['user'];
$cur_attack[] = $row['cur_attack'];

?>

<tr>
<td align="center"><font color="#d3d3d3"></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['user'];?></font></td>
<td align="center"><font color="#d3d3d3"></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['cur_attack'];?></font>    </td></tr>

<?php
}
?>

</table

Here is a link to the page as is now:

ok i wrote up the query the way you showed and now i get Column 'user' in field list is ambiguous

$sql = "SELECT user, cur_attack , experience.*
FROM curstats 
 LEFT JOIN experience 
 ON curstats.user = experience
 order by cur_attack desc LIMIT 25";
$result = mysql_query($sql) or die(mysql_error());



$user = $cur_attack = $exp_attack = array();
while($row = mysql_fetch_assoc($result)) {
$user[] = $row['user'];
$cur_attack[] = $row['cur_attack'];
$exp_attack[] = $ROW['exp_attack'];
?>

<tr>
<td align="center"><font color="#d3d3d3"></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['user'];?></font></td>
<td align="center"><font color="#d3d3d3"></font><?php echo $row['exp_attack']; ?></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['cur_attack'];?></font>   </td></tr>
3
  • you have to write joined queries to fetch other tables value if you key with username Commented Dec 30, 2013 at 0:18
  • note that this method (mysql_) is deprecated. See mysqli and/or PDO Commented Dec 30, 2013 at 0:19
  • thank you very much i know it is a depricated value and i will switch over if i ever make this site public for now im kind of just messing around Commented Dec 30, 2013 at 0:33

1 Answer 1

1

just use the join in your query

 SELECT 
      c.user,
      c.cur_attack,
      e.exp_attack
 FROM curstats c
 LEFT JOIN experience e
 ON c.user = e.user
 ORDER BY c.cur_attack desc LIMIT 25
Sign up to request clarification or add additional context in comments.

5 Comments

wrote up the array the way you sad and now get Column 'user' in field list is ambiguous i went ahead and listed the array i rewrote above if you would take a look
change in my example: other_table.* to other_table.column_you_want_to_display (or columns)
still no go about to just rewrite all of this cant figure it out'
ok man i got it working good now. how can i achieve displaying rank. in the left column rank every time the array loops the number should go up by one starting at 1
simply.. add variable to your loop. Ex. add $rank=1 before 'while' and $rank++ in loop. And then display it.

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.