rcorlew Posted March 26, 2007 Share Posted March 26, 2007 Okay, I am having problems with querying my db by multiple id(s). To clarify more, I am trying to match the id of each row to an array that has been formatted into a string seperated by commas. Here is my code to see if anyone can help. <?php $str = "1,2,3,4"; $query = "SELECT * FROM table WHERE p_id = IN($str)"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/44279-solved-my-sql-select-multiple-multiple-rows/ Share on other sites More sharing options...
sps Posted March 26, 2007 Share Posted March 26, 2007 What type of column is p_id? If it is not an INT then you need each item in your in() clause enclosed in quotes. If it is an INT column then it should work as written, does it give an error or just return no rows? Quote Link to comment https://forums.phpfreaks.com/topic/44279-solved-my-sql-select-multiple-multiple-rows/#findComment-215084 Share on other sites More sharing options...
rcorlew Posted March 26, 2007 Author Share Posted March 26, 2007 It is a tinint column, it returns only the first result, the result can be different based on the first number in the string, is there something like CHAR() or smething I can try Quote Link to comment https://forums.phpfreaks.com/topic/44279-solved-my-sql-select-multiple-multiple-rows/#findComment-215086 Share on other sites More sharing options...
jitesh Posted March 26, 2007 Share Posted March 26, 2007 $query = "SELECT * FROM table WHERE p_id IN (".$str.")"; Quote Link to comment https://forums.phpfreaks.com/topic/44279-solved-my-sql-select-multiple-multiple-rows/#findComment-215174 Share on other sites More sharing options...
rcorlew Posted March 26, 2007 Author Share Posted March 26, 2007 Mucho thanks, the '=' kept loosing me! Quote Link to comment https://forums.phpfreaks.com/topic/44279-solved-my-sql-select-multiple-multiple-rows/#findComment-215740 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.