SkyRanger Posted February 15, 2013 Share Posted February 15, 2013 I am having a problem with selecting from 2 columns. select from help where to_name = '$loggedin' and fr_name='$loggedin' This is not right, I know what because it is not working. Can anybody tell me what the proper code would be for this. Thanks Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/ Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 Well you aren't selecting any columns. Why don't you post your ACTUAL code. Including the mysql error and final query as demonstrated in my debugging your sql link. Edit: Also, it appears you're trying to select a message that someone apparently sent to themselves. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412648 Share on other sites More sharing options...
SkyRanger Posted February 15, 2013 Author Share Posted February 15, 2013 $queryhd = "SELECT * from help where to_name='$loggedin' and fr_name='$loggedin' and opened IN ('y', 'n', 'r', 'c') order by 'time_sent' DESC"; $resulthd = $mysqli->query($queryhd) or die($mysqli->error.__LINE__); No errors are reporting. What I am trying to do is show messages sent and receied from a user. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412649 Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 A single message probably won't have the same user in the to and from column will it. Think about it. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412651 Share on other sites More sharing options...
SkyRanger Posted February 15, 2013 Author Share Posted February 15, 2013 No. For example: mid to_name from_name 1 user1 user2 2 user2 user3 3 user2 user1 I am trying to figure out how to show all message that user 2 has sent or received. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412654 Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 So the from_user _____ to_user will be that username. Fill in that blank. (BTW: you really should be the PK, not usernames). Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412655 Share on other sites More sharing options...
SkyRanger Posted February 15, 2013 Author Share Posted February 15, 2013 (BTW: you really should be the PK, not usernames). ? - sorry confused. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412658 Share on other sites More sharing options...
Jessica Posted February 15, 2013 Share Posted February 15, 2013 You should use user_id not username to store relational data. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412659 Share on other sites More sharing options...
SkyRanger Posted February 15, 2013 Author Share Posted February 15, 2013 ok, believe I got it to work, so far so good select * from help where fr_name = '$loggedin' or to_name = '$loggedin' Thank Jessica for the tip. Will be changing it over. Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.