Asheeown Posted January 24, 2007 Share Posted January 24, 2007 I'm building a page for a customer to search every log from their ID. When they login the ID is set to a session, However the customer may have two or more IDs so that sessions for example would be "000500,000501" now what I want to do is search in the table "rated_cdrs" to match "000500" and "000501" to the column "Originating_TG" in that table, any idea on how to? Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/ Share on other sites More sharing options...
effigy Posted January 24, 2007 Share Posted January 24, 2007 You can store the ids in an array, or use split to turn the string into one. After you have this, use indexes 0 and 1 in your SQL. Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167792 Share on other sites More sharing options...
Asheeown Posted January 24, 2007 Author Share Posted January 24, 2007 The ID's in the session are separated by a comma so I can explode that, but what do you mean by the 0th and 1st index in my SQL? Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167793 Share on other sites More sharing options...
effigy Posted January 24, 2007 Share Posted January 24, 2007 Use the pieces of the array (exploded string) in your SQL. Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167800 Share on other sites More sharing options...
Asheeown Posted January 24, 2007 Author Share Posted January 24, 2007 Well I'm trying to call the logs for the Id(s) in session so how would my where statement go if I were to have more than one Id to get logs for? Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167802 Share on other sites More sharing options...
effigy Posted January 24, 2007 Share Posted January 24, 2007 Since your ids are already separated by a comma, drop them in an [b]IN[/b]:[code]<pre><?php $ids = array ( '1', '1,2', '1,2,3', '111', '111,222', '111,222,333', ); foreach ($ids as $id) { echo "SELECT ... WHERE id IN ($id)<br>"; }?></pre>[/code]Are the leading zeros important? Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167807 Share on other sites More sharing options...
Asheeown Posted January 24, 2007 Author Share Posted January 24, 2007 Yeah the leading zeros are part of the Id in both tables Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167808 Share on other sites More sharing options...
effigy Posted January 24, 2007 Share Posted January 24, 2007 [code]<pre><?php $ids = array ( '1', '1,2', '1,2,3', '111', '111,222', '111,222,333', '0005000', ); foreach ($ids as $id) { $id = preg_replace('/(\d+)/', '"\1"', $id); echo "SELECT ... WHERE id IN ($id)<br>"; }?></pre>[/code] Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167812 Share on other sites More sharing options...
Asheeown Posted January 24, 2007 Author Share Posted January 24, 2007 I got it, thanks very much for your expertise Link to comment https://forums.phpfreaks.com/topic/35461-two-or-more-conditions-in-a-where-statement/#findComment-167818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.