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
LVL 3
3xtr3m3dAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Lukasz ChmielewskiConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.