Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:35:43+00:00 2026-06-04T17:35:43+00:00

I am trying to get a select list with values from $staff The bit

  • 0

I am trying to get a select list with values from $staff
The bit i am struggling is selecting the staff that are already enrolled from $entry->enrolments.

If the $staff id exists in $entry->enrolments select it in the select list

$entry = Record from mysql

$staff = list of staff in an array.

$entry->enrolments = comma seperated values of enrolled staff

<select name="tutor[]" id="tutor" multiple="multiple" size="5" class="required" title="Select Staff">

<?php
    $entry = get_record("staff_development", "id", $id);
    $staff = get_records("user", "deleted", "0", "lastname ASC", "id,firstname,lastname,idnumber");
    $sdenrolments=array($entry->enrolments);
    $people = explode(",", $entry->enrolments);


    foreach($staff as $tutor){
    foreach($people as $person){

    if($tutor->id>1)echo '<option value="'.$tutor->id.'"';
    if ($person==$tutor->id) {echo 'selected="selected"';}
    echo '>'.$tutor->lastname.' '.$tutor->firstname.'</option>';
    }
    }
?>

</select>

Any help/guidance would be greatly appreciated.
Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:35:45+00:00Added an answer on June 4, 2026 at 5:35 pm

    in_array is the easiest way to tell if a value is in an array 🙂 Replace your loops with this:

    foreach($staff as $tutor){
        echo '<option value="'.$tutor->id.'"';
        if(in_array($tutor->id, $people))
            echo 'selected="selected"';
        echo '>'.$tutor->lastname.' '.$tutor->firstname.'</option>';
    }
    

    You might also want to rename your variable from people to enrolled_staff or something a bit more clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the values from my select list on a jquery
Im trying to get values from a ListBox that has multiselection and dynamic ListItems
I'm trying to get a list of values to display upon a selection from
I'm trying to get a list of the unique values from a field called
Im trying to get a value or a text from the select option tag
I'm trying to SELECT, and get a unique result set, from a MySQL database,
I'm trying to get a list of dates from my table, which contains a
Here's an ASPX code snippet from when I was trying to get multiple values
I am trying to get a list of product id's that do not have
I am trying to get just the select element and not its options. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.