Jump to content

Complicated PHP/MSSQL Query - help needed


laural

Recommended Posts

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!  :D

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.