• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[PHP] Ranking code

Elite Diviner
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.
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>';
?>
 
Newbie Spellweaver
Joined
Aug 14, 2009
Messages
22
Reaction score
16
If I understand your query correctly, id and user_id is the relation of your two tables. If so, try this query:

$query = mysql_query('SELECT * FROM `users` INNER JOIN `skills` ON users.id = skills.user_id ORDER BY skills.taming LIMIT 10');
 
[̲̅$̲̅(̲̅1̲̅)̲̅$ ̲̅]
Joined
May 4, 2008
Messages
831
Reaction score
741
You have to use JOIN with your query. Goole is your buddy here :)

Sent from some remote location using Tapatalk...
 
Elite Diviner
Joined
Aug 15, 2008
Messages
489
Reaction score
43
If I understand your query correctly, id and user_id is the relation of your two tables. If so, try this query:

$query = mysql_query('SELECT * FROM `users` INNER JOIN `skills` ON users.id = skills.user_id ORDER BY skills.taming LIMIT 10');
Exactly what I was looking for. Thank you!


You have to use JOIN with your query. Goole is your buddy here :)

Sent from some remote location using Tapatalk...
I tried googling, but probably not with the correct words.
 
Back
Top