wright67uk Posted March 2, 2013 Share Posted March 2, 2013 I'm looking to only return rows where the first two letters of $_attributeSelection["backp1"] are GBI'm sure I need to use strpos somehow, but Im not sure how to use it with my code can anyone show me how? <?php foreach ($selections as $_selection) { $_attributeSelection = $_selection->attributes(); ?> <tr> <td> <?php echo $_attributeSelection["name"] ?> </td> <td> <b><?php echo $_attributeSelection["backp1"] ?></b><br/> </td> </tr> Link to comment https://forums.phpfreaks.com/topic/275111-display-row-where-strpos-01-are-matched/ Share on other sites More sharing options...
kicken Posted March 2, 2013 Share Posted March 2, 2013 If you are interesting in the first two letters specifically rather than GB appearing anywhere in the string, then use substr. if (substr($_attributeSelection['backp1'], 0, 2)=='GB'){ } Link to comment https://forums.phpfreaks.com/topic/275111-display-row-where-strpos-01-are-matched/#findComment-1415958 Share on other sites More sharing options...
Barand Posted March 2, 2013 Share Posted March 2, 2013 You could also do it in the MySql query ... WHERE SUBSTRING(backp1 ,1, 2) = 'GB' Link to comment https://forums.phpfreaks.com/topic/275111-display-row-where-strpos-01-are-matched/#findComment-1415979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.