Jump to content

Mysql query rewrite accessing multiple tables.


Recommended Posts

I need assistance rewritting this query do it look correct?

$en['totalm'] = mysql_num_rows(mysql_query("SELECT m_type FROM `rate_members` WHERE `rate_referrals`.`ref_userid` = '{$userid}` AND `rate_referrals`.`ref_mem` = `rate_members`.`m_id` AND `rate_members`.`m_type` = 1 "));

 

Go to rate_members select the m_type field, then go to table rate_referrals and grab all rows where there ref_userid = $userid then look at the ref_mem, ref_mem = rate_members.m_id look at the m_type table and count all ref_mem's that have m_type =1

 

 

I think most of this is right, but my question is $theuser i have WHERE `m_user` = $ref['ref_userid'], ref_userid is a number (userid) so what I'm trying to do is use that userid number reference rate_members row where m_id = ref_userid then get the m_user (username). will the coding i'm using work properly?

 

$ref = mysql_fetch_array(mysql_query("SELECT `ref_id`,`ref_userid`,`ref_mem`,`ref_status` FROM `rate_referrals` WHERE `ref_userid` = '{$userid}'");

$theuser = mysql_query("SELECT `m_id`, `m_date`, `m_type`, `m_user` FROM `rate_members` WHERE `m_id` = '".$ref['ref_userid']."'");

while($row = mysql_fetch_array($theuser)) {

 

echo ".$row['m_user']. -  .$row['m_type']. - .$row['m_date']. - .$ref['ref_status'].\n";

 

}

is this is what you want?

 

SELECT `m_id`, `m_date`, `m_type`, `m_user` FROM `rate_members`,`rate_referrals` where `rate_members`.`m_id` =`rate_referrals`.`ref_userid` AND `rate_referrals`.`ref_userid` = '$userid';

is this is what you want?

 

SELECT `m_id`, `m_date`, `m_type`, `m_user` FROM `rate_members`,`rate_referrals` where `rate_members`.`m_id` =`rate_referrals`.`ref_userid` AND `rate_referrals`.`ref_userid` = '$userid';

 

which one if that for?

 

Is it possible to Msg you on Ymsg, AIM or MSN... i'm a little confused

damn it. where the code has gone

 

SELECT `m_id`, `m_date`, `m_type`, `m_user` FROM `rate_members`,`rate_referrals` where `rate_members`.`m_id` =`rate_referrals`.`ref_userid` AND `rate_referrals`.`ref_userid` = '$userid';

damn it. where the code has gone

 

SELECT `m_id`, `m_date`, `m_type`, `m_user` FROM `rate_members`,`rate_referrals` where `rate_members`.`m_id` =`rate_referrals`.`ref_userid` AND `rate_referrals`.`ref_userid` = '$userid';

 

is this replacing the $ref & $theuser?

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.