• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

php array help

Hi

im storing records like this

 db
section contains the office numbers which this file should available and my session contains the office number which user logged in

so how to check whether session office number is contain in section or not?

Thanks
0
3xtr3m3d
Asked:
3xtr3m3d
2 Solutions
 
Ray PaseurCommented:
You can use LIKE in the query, however this data base table is misdesigned.  Each column should contain only one value.  In other words, you should have three rows for this data instead of one.
0
 
Ray PaseurCommented:
Here is information that might be helpful.  Read the top five responses and you'll be way ahead in understanding data base design.
http://lmgtfy.com/?q=Should+I+Normalize+My+Database

;-)

HTH, ~Ray
0
 
ansudhindraCommented:
Assuming, section is an array, here is the piece of code which returns trur if logged in user section number is present in the section.

sessionSectionVar - is the section number of user stored in the session.

<?php
function myfunction($ae)
{
if ($ae===sessionSectionVar)
  {
  return true;
  }
return false;
}
print_r(array_filter($ae,"myfunction"));
?>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Lukasz ChmielewskiCommented:
Ray's right BUT what if there are 200 offices ?
Get the value from the table like
(...)

$myarray = explode($row[section]);
if(in_array($_SESSION[office],$myarray)) echo"found";
0
 
3xtr3m3dAuthor Commented:
yeah currently i have 15 offices and also that can be increased in future
0
 
Ray PaseurCommented:
15 offices or 200 or 20,000 offices will not really matter.  If your tables are indexed correctly the size and speed of the app will be just fine.  Anyway thanks for the points and good luck with it, ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now