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

Link to comment
Share on other sites

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"; 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.