JonnySnip3r Posted August 24, 2010 Share Posted August 24, 2010 Hey guys i have a query that select from multiple tables and works fine however i have the same field name in each table called:: member_id but i want to select specifically the member_id from table1 do i need to change the name when i loop through them? i really dont want to do that but if it confuses php unless is there a way when doin a while loop i specify what table i want it from? while($row = mysql_fetch_array($query)){ $member_id = $row['member_id']; } Link to comment https://forums.phpfreaks.com/topic/211607-php-mysql_fetch_array-problem/ Share on other sites More sharing options...
kenrbnsn Posted August 24, 2010 Share Posted August 24, 2010 Please post your query. Ken Link to comment https://forums.phpfreaks.com/topic/211607-php-mysql_fetch_array-problem/#findComment-1103096 Share on other sites More sharing options...
JonnySnip3r Posted August 24, 2010 Author Share Posted August 24, 2010 hey dude here is the problem:: $friend_query = mysql_query("SELECT * FROM member_friends WHERE my_id = '$my_id'"); while($row = mysql_fetch_array($friend_query)){ $friend_id = $row['friend_id']; $sql = mysql_query("SELECT a.*,b.* FROM member_topics as a, member_friends as b WHERE (a.member_id = b.my_id) AND ((b.friend_id = '$friend_id') AND b.my_id = '$my_id') ORDER BY a.message_id DESC"); while($row = mysql_fetch_array($sql)){ $message_id = $row['message_id']; $member_id = $row['member_id']; $message_contents = $row['message_contents']; $message_date = $row['message_date']; $message_type = $row['message_type']; $message_reported = $row['message_reported']; $mem_image = get_member_image_from_member_id($member_id); $member_name = get_member_name_from_member_id($member_id); // Clean:: $message_cleaned = bad_word_filter($message_contents,$my_id,$message_id); echo "<div id=\"message_section\">"; echo "<img src='profile/images/$mem_image' alt='Message Image' />"; echo "<h5><a href='http://mysite.com/$member_name'>$member_name</a> - $message_date</h5>"; echo "<p>$message_cleaned</p>"; echo "</div><!-- end message_section -->"; } } when i loop i dont think its passing the new value into the while loop hence the reason the query isnt working is this correct? or is there a easy way i always seem to do the long way haha Thanks!!! Link to comment https://forums.phpfreaks.com/topic/211607-php-mysql_fetch_array-problem/#findComment-1103150 Share on other sites More sharing options...
AbraCadaver Posted August 24, 2010 Share Posted August 24, 2010 It confuses me why you have a member_id in both tables and you are joining on a different my_id, but anyway, specify the columns you want to select instead of using *: SELECT a.member_id, a.another1, a.another2, b.something1, b.something2 Link to comment https://forums.phpfreaks.com/topic/211607-php-mysql_fetch_array-problem/#findComment-1103165 Share on other sites More sharing options...
JonnySnip3r Posted August 24, 2010 Author Share Posted August 24, 2010 Thanks dude i have a member_id in each one because i can then relate what ever is in that table to the member. Thanks!! Link to comment https://forums.phpfreaks.com/topic/211607-php-mysql_fetch_array-problem/#findComment-1103201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.