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"; } Link to comment https://forums.phpfreaks.com/topic/68659-mysql-query-rewrite-accessing-multiple-tables/ 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'; Link to comment https://forums.phpfreaks.com/topic/68659-mysql-query-rewrite-accessing-multiple-tables/#findComment-345251 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 Link to comment https://forums.phpfreaks.com/topic/68659-mysql-query-rewrite-accessing-multiple-tables/#findComment-345419 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'; Link to comment https://forums.phpfreaks.com/topic/68659-mysql-query-rewrite-accessing-multiple-tables/#findComment-345434 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? Link to comment https://forums.phpfreaks.com/topic/68659-mysql-query-rewrite-accessing-multiple-tables/#findComment-345738 Share on other sites More sharing options...
fenway Posted September 11, 2007 Share Posted September 11, 2007 Yes, and a JOIN would be better. Link to comment https://forums.phpfreaks.com/topic/68659-mysql-query-rewrite-accessing-multiple-tables/#findComment-346207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.