- Joined
- Aug 15, 2008
- Messages
- 489
- Reaction score
- 43
There are 2 tables, users and skills.
In the users table, I have id, username, lastlogin and party.
In the skills table, I have user_id and row for each skill.
What I am trying to do, is basically load data from both of those tables, then display the username correctly next to the skills. What I've tried so far is loading the data from the both tables with SELECT * FROM `users` , `skills` and then just echoing the username next to the skills, but that gives random names next to the skills.
So what I need to know is, how can I basically load everything from both tables, then make it so username row from users table is basically same as user_id from the skills table, so it would display the username next to the skills correctly?
Here is my current code.
In the users table, I have id, username, lastlogin and party.
In the skills table, I have user_id and row for each skill.
What I am trying to do, is basically load data from both of those tables, then display the username correctly next to the skills. What I've tried so far is loading the data from the both tables with SELECT * FROM `users` , `skills` and then just echoing the username next to the skills, but that gives random names next to the skills.
So what I need to know is, how can I basically load everything from both tables, then make it so username row from users table is basically same as user_id from the skills table, so it would display the username next to the skills correctly?
Here is my current code.
Code:
<?php
@error_reporting ( E_ALL ^ E_WARNING ^ E_NOTICE );
@ini_set ( 'display_errors', true );
@ini_set ( 'html_errors', false );
@ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE );
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());
// Table
echo '<table>';
echo '<tr>';
echo '<td>User</td>';
echo '<td>Power</td>';
echo '<td>Taming</td>';
echo '<td>Mining</td>';
echo '<td>Woodcutting</td>';
echo '<td>Repair</td>';
echo '<td>Unarmed</td>';
echo '<td>Herbalism</td>';
echo '<td>Excavation</td>';
echo '<td>Archery</td>';
echo '<td>Swords</td>';
echo '<td>Axes</td>';
echo '<td>Acrobatics</td>';
echo '<td>Fishing</td>';
echo '</tr>';
// Output the data
$query = mysql_query('SELECT * FROM `users` , `skills` ORDER BY `taming` LIMIT 10');
while($row = mysql_fetch_assoc($query)){
// $power_level = .$row['user']. + .$row['taming']. + .$row['mining']. + .$row['woodcutting']. + .$row['repair']. + .$row['unarmed']. + .$row['herbalism']. + .$row['excavation']. + .$row['archery']. + .$row['swords']. + .$row['axes']. + .$row['acrobatics']. + .$row['fishing'].;
echo '<tr>';
echo '<td>'.$row['user'].' - '.$row['user_id'].'</td>';
// echo '<td>'. $power_level .'</td>';
echo '<td>'.$row['taming'].'</td>';
echo '<td>'.$row['mining'].'</td>';
echo '<td>'.$row['woodcutting'].'</td>';
echo '<td>'.$row['repair'].'</td>';
echo '<td>'.$row['unarmed'].'</td>';
echo '<td>'.$row['herbalism'].'</td>';
echo '<td>'.$row['excavation'].'</td>';
echo '<td>'.$row['archery'].'</td>';
echo '<td>'.$row['swords'].'</td>';
echo '<td>'.$row['axes'].'</td>';
echo '<td>'.$row['acrobatics'].'</td>';
echo '<td>'.$row['fishing'].'</td>';
echo '</tr>';
}
echo '</table>';
?>