Hi All,
Im stuck again - just when I think I know something I prove I dont!
Im looking to create a drop down list which is pre-selected from date in 2 mysql data bases. This MUST be coded in procedural PHP.
What I have is 2 databases. One (called "Users") holds the names of people and a corresonding ID number thus:
ID ..........
Name
1 ........... Alan
2 ........... Brian
3 ........... Chris
4 ........... Denise
Another table (called "Data") has a few columns, one of which is called "User_ID". These user ids are related to the "Users" table. If the column has a 1 in it the that row was inserted by Alan.
What I want is a dropdown menu on my web page (which is written in PHP) where if a user has input the row of data in the "Data" database then the name of that user comes pre-selected in the dropdown menu. So if the row in "Data" has 3 in the "User_ID" column, then "Chris" is shown pre-selected in the dropdown menu.
What I have so far (and its the closest I have got in 5 days of struggling) is this code (assume I am connected to the databases):
select name="tracking" id="current_user"
<?php
$row = mysqli_query($conn, "SELECT * FROM Data");
$result = mysqli_query($conn, "SELECT ID, Name FROM Users");
while($row=mysqli_fetch_array($result)) {
$selected = (($value["ID"]) === ($row["ID"]) ? 'selected' : '');
$UserID = (($value["ID"]) === ($row["ID"]) ? $value["Name"] : '');
echo '<option value='.$UserID.' '.'select= '.$selected.'>'$row['Name']'</option>';
}
?>
</select>
Can anyone help me make this work please? It gives the wrong name - it always returns the last name on the list regardless of the line in the "Data" database.
Any help would be appreciated.
- Posts
- 999
- Registration date
- Saturday January 17, 2015
- Status
- Moderator
- Last seen
- August 11, 2019
195 -Im still having trouble with this. I had forgotten about joins and need to relearn this. I'm sure you have put me on the right track but I need to experiment a bit. Have a coke while you wait :^)
- Posts
- 999
- Registration date
- Saturday January 17, 2015
- Status
- Moderator
- Last seen
- August 11, 2019
195 -- Posts
- 12936
- Registration date
- Monday June 3, 2013
- Status
- Moderator
- Last seen
- September 3, 2019
1342 -Select DISTINCT will only return One per user!
I assumed you were building the query already using the user list. Sorry for making an ASS out of ME!