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 Quote 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 (edited) 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. Edited February 15, 2013 by Jessica Quote 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. Quote 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. Quote 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 (edited) 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. Edited February 15, 2013 by SkyRanger Quote 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). Quote 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. Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/274532-select-from-2-columns/#findComment-1412701 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.