Jump to content

Selecting columns from 2 separate tables trouble


MasterACE14

Recommended Posts

hey guys,

 

I'm having trouble with a query, it was working fine when I was selecting columns from just the 1 table, but when I try and select from 2 tables at the same time its showing the first result in the table over and over again, instead of all the results.

 

here's my code(relevant parts only):

<?php
    $query  = "SELECT * FROM `cf_users`,`cf_users2` ORDER BY `cf_users`.`rank` asc LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

while ($a_row = mysql_fetch_array( $result ) ) {

	$all_id = stripslashes($a_row['id']);
	$all_name = stripslashes($a_row['username']);
	$all_rank = stripslashes($a_row['rank']);
	$all_title = stripslashes($a_row['title']); // this is the only column from the second table (cf_users2)
	$all_race = stripslashes($a_row['race']);
	$all_money = stripslashes($a_row['money']);
	$all_covertaction = stripslashes($a_row['covertaction']);

 

any help is greatly appreciated!  :)

 

Regards ACE

i think you need a WHERE clause tying the two tables together. otherwise, you'll get every possible version of table 1 and table 2 together. something more like:

 

$query  = "SELECT * FROM `cf_users`,`cf_users2` WHERE cf_users.id = cf_users2.other_id ORDER BY `cf_users`.`rank` asc LIMIT $limitvalue, $limit"; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.