acctman Posted September 10, 2007 Share Posted September 10, 2007 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"; } Quote Link to comment Share on other sites More sharing options...
Illusion Posted September 10, 2007 Share Posted September 10, 2007 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'; Quote Link to comment Share on other sites More sharing options...
acctman Posted September 10, 2007 Author Share Posted September 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
Illusion Posted September 10, 2007 Share Posted September 10, 2007 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'; Quote Link to comment Share on other sites More sharing options...
acctman Posted September 11, 2007 Author Share Posted September 11, 2007 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 11, 2007 Share Posted September 11, 2007 Yes, and a JOIN would be better. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.