php array help

Posted on 2011-05-11
Last Modified: 2012-05-11

im storing records like this

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?

Question by:3xtr3m3d
    LVL 107

    Accepted Solution

    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.
    LVL 107

    Expert Comment

    by:Ray Paseur
    Here is information that might be helpful.  Read the top five responses and you'll be way ahead in understanding data base design.


    HTH, ~Ray
    LVL 13

    Expert Comment

    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.

    function myfunction($ae)
    if ($ae===sessionSectionVar)
      return true;
    return false;
    LVL 27

    Assisted Solution

    by:Lukasz Chmielewski
    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";
    LVL 3

    Author Comment

    yeah currently i have 15 offices and also that can be increased in future
    LVL 107

    Expert Comment

    by:Ray Paseur
    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

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now