Riparian Posted October 2, 2009 Share Posted October 2, 2009 Is there a way I can limit the % wildcard to only one character e.g. $stock_number=100a Select all where stock_number like $stock_number% will also return stock number 1000a where all i want is 100a, 100b, 100c etc Any help is really appreciated Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/ Share on other sites More sharing options...
Mchl Posted October 2, 2009 Share Posted October 2, 2009 Use _ to match single character Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928912 Share on other sites More sharing options...
Riparian Posted October 2, 2009 Author Share Posted October 2, 2009 Thank you very much for the reply Mchl Could you possibly give me an example where i could match the last digit to any alpha (not number) I have been trying all afternoon using _ and things like REGEXP '^$model.{1}$' but I cant get the desired results. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928925 Share on other sites More sharing options...
Mchl Posted October 2, 2009 Share Posted October 2, 2009 SELECT '100a' RLIKE '100[a-z]'; -> 1 SELECT '1000' RLIKE '100[a-z]'; -> 0 Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928927 Share on other sites More sharing options...
Riparian Posted October 2, 2009 Author Share Posted October 2, 2009 Thanks for the help. I have tried every combination and only get Parse errors. Could you please advise me where this is going wrong $sql="select * from $table WHERE $model_number RLIKE '$model_number[[a-z]]' and in_stock='T' "; Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928941 Share on other sites More sharing options...
Riparian Posted October 2, 2009 Author Share Posted October 2, 2009 Sorry ... Mistakenly added a $ to the Model_number field in the first reply Thanks for the help. I have tried every combination and only get Parse errors. Could you please advise me where this is going wrong $sql="select * from $table WHERE model_number RLIKE '$model_number[[a-z]]' and in_stock='T' "; Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928944 Share on other sites More sharing options...
Mchl Posted October 2, 2009 Share Posted October 2, 2009 Try: <?php $sql="select * from $table WHERE model_number RLIKE '{$model_number}[a-z]' and in_stock='T' "; Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928957 Share on other sites More sharing options...
Riparian Posted October 2, 2009 Author Share Posted October 2, 2009 Thank you very much for all your help. It works exactly as required and I have learned something for the future. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/176258-solved-help-with-like/#findComment-928963 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.