laural Posted April 27, 2012 Share Posted April 27, 2012 I have a stored procedure on MSSQL that returns a list of results. This works fine. The results that are returned may or may not be allowed to be seen by the end user. So, if 10 results are returned, maybe 7 of them are allowed to be viewed by the end user. There is a PHP SESSION variable that contains a bunch of codes that is compared to a variable returned from the search result. When these match, the result can be seen by the user. So, I am using a php if statement that echos the result based on the result of the if statement. That works fine. What does not work is the found count for the array. For example, if 10 are found, it returns 10, but the if statement removes 3 making 7 of the results viewable. So, is there a way to iterate through an array result set in PHP and remove results based on an if statement creating a new array? Hope this is not too confusing! Link to comment https://forums.phpfreaks.com/topic/261713-complicated-phpmssql-query-help-needed/ Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 Sure. $old_array = array(1,2,3,4,5,6,7,8,9,10); $new_array = array(); foreach($old_array as $old) { if ($old != 3 && $old != 5 && $old != 7) { $new_array[] = $old; } } /* $new_array = Array ( [0] => 1, [1] => 2, [2] => 4, [3] => 6, [4] => 8, [5] => 9, [6] => 10 ) */ Link to comment https://forums.phpfreaks.com/topic/261713-complicated-phpmssql-query-help-needed/#findComment-1341123 Share on other sites More sharing options...
laural Posted April 27, 2012 Author Share Posted April 27, 2012 Thank You!!!!! Just what I needed! Link to comment https://forums.phpfreaks.com/topic/261713-complicated-phpmssql-query-help-needed/#findComment-1341158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.