Search code examples
phphtmlmysqldropdownbox

HTML DropDown with Mysqli data and data selection


I have an html dropdown list which gets the data from mysql table. I have a second table where I can see which equipment has already been selected for another user for the day.

My question is:

  • How do I not display that equipment (BowCode and its Information) and instead go to the next entry.

  • It's possible that multiple equipment have been already selected for the day for other users.

My code:

$BowDropDown = mysqli_query($mysqli, "SELECT * FROM equipment order by BowCode ASC");

while ($row = $BowDropDown->fetch_assoc()){

    if($row['BowCode'] != $BowDropDownDayCheck){}

    if($row['Recurve'] =='1'){
        $value = 'Recurve';
    } else if ($row['Compound'] == '1'){
        $value = 'Compound';
    } else if ($row['Longbow'] == '1'){
        $value ='Longbow';
    }
echo "<option value= " . $row['BowCode'] . ">" . $value . " - " . $row['BowCode'] . " - " . $row['Info'] . " - " . $row['Poundage'] . "</option>";
}

I don't know if it is possible or not but maybe the values that are displayed in the dropdown can be visualised like a table view.

table from where the Equipment is stored

tabele where the users are stored with the Equipment the use for the day


Solution

  • This one does the job

    SELECT 
       b.id, b.BowCode, b.Info
    FROM Equipment AS b
    LEFT JOIN 
      (SELECT a.BowID
       FROM comeandtrydaysparticipant AS a
       WHERE a.`date`="2018-01-26"
       GROUP BY a.BowID
      ) AS c
    ON c.BowID = b.BowCode
    WHERE c.BowID IS NULL
    ;
    

    It selects all items not in comeandtrydaysparticipant for a particular day.

    And the proof is in the pudding