Make preselected dropdown list -2 mysql databases
Solved/Closed
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
-
Updated on Oct 19, 2018 at 09:37 AM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Nov 27, 2018 at 03:44 PM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Nov 27, 2018 at 03:44 PM
Related:
- Make preselected dropdown list -2 mysql databases
- Tentacle locker 2 - Download - Adult games
- Fnia 2 - Download - Adult games
- Feeding frenzy 2 download - Download - Arcade
- Euro truck simulator 2 download free full version pc - Download - Simulation
- Resident evil 2 remake free download - Download - Horror
3 responses
You have to build a query with a join.
Try something like this:
SELECT name.Data, id.users
FROM Data
INNER JOIN Users ON Data.ID=Users.ID;
Inner joins brings only data that matches and exists ON BOTH table.
Left Join brings data from the Left table, and only the matching from the right.
Right Join brings all from right table, and only the matching from left.
I like Playlinda GEOGRAPHICALLY CHALLENGED®! Thanks!
Try something like this:
SELECT name.Data, id.users
FROM Data
INNER JOIN Users ON Data.ID=Users.ID;
Inner joins brings only data that matches and exists ON BOTH table.
Left Join brings data from the Left table, and only the matching from the right.
Right Join brings all from right table, and only the matching from left.
I like Playlinda GEOGRAPHICALLY CHALLENGED®! Thanks!
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
149
Oct 28, 2018 at 04:46 AM
Oct 28, 2018 at 04:46 AM
Ok, I have found why my first aproach doesn't work. It seems the
lines keep looping when in a while loop until the last item in the array is looked at. Therefore the value of the variable will always be the value of the last entry in the array.
I have only entered this finding in the hope it helps others in the same situation - sorry no fix yet.
ac3mark - I havent had chance to look into your last suggestion. I will get onto it next week - unfortunately the wife wants to go on holiday!
$selected = (($value["ID"]) === ($row["ID"]) ? 'selected' : '');
$UserID = (($value["ID"]) === ($row["ID"]) ? $value["Name"] : '');
lines keep looping when in a while loop until the last item in the array is looked at. Therefore the value of the variable will always be the value of the last entry in the array.
I have only entered this finding in the hope it helps others in the same situation - sorry no fix yet.
ac3mark - I havent had chance to look into your last suggestion. I will get onto it next week - unfortunately the wife wants to go on holiday!
Well first of all, do not chop the two into separate Queries, it is one. So it would be like this:
Where 0 and 1 are the index numbers returned by the Query. Index[0]=Name.date and index[1]=id.users as indicated by the join in the SQL!
If this does not produce what you are asking, then you will need to build one array on Users. Build a loop of Queries that will return one row per user. Then you will run another query of what "items" are attached to that user, storing them in another multidimensional array. So, the first array will be of:
Select Distinct users from user table
result
Mary
Jorge
Fred
Those returned values are stored into an array of users:
Users(0)=Mary
Users(1)=Jorge
Users(2)=Fred
Now, when you query based on that element, you build another array for just that specific user:
"Select ticket_numbers where user = " & USER(0) & ";"
Return values are something like:
"3456"
"4321"
"8976"
Which represents the ticket numbers in this example. So when those are returned, we load them into another array called tickets. This array has two values to it, the user, and the ticket. So, up to know we have:
Ticket(0)="USER(0),3456"
Ticket(1)="USER(0),4321"
Ticket(2)="USER(0),8976"
After the second loop has finished, you can output the link as in:
Build a loop:
I found this most basic that describe in PHP. I am an ASP, VBA, and C++ guy. The theory is still the same!
$row="SELECT DISTINCT name.Data, id.users FROM Data INNER JOIN Users ON Data.ID=Users.ID;"
while($row=mysqli_fetch_array($result)) {
echo '<option value='.$row[0].' '.'select= '.$selected.'>'$row[1]'</option>';
Where 0 and 1 are the index numbers returned by the Query. Index[0]=Name.date and index[1]=id.users as indicated by the join in the SQL!
If this does not produce what you are asking, then you will need to build one array on Users. Build a loop of Queries that will return one row per user. Then you will run another query of what "items" are attached to that user, storing them in another multidimensional array. So, the first array will be of:
Select Distinct users from user table
result
Mary
Jorge
Fred
Those returned values are stored into an array of users:
Users(0)=Mary
Users(1)=Jorge
Users(2)=Fred
Now, when you query based on that element, you build another array for just that specific user:
"Select ticket_numbers where user = " & USER(0) & ";"
Return values are something like:
"3456"
"4321"
"8976"
Which represents the ticket numbers in this example. So when those are returned, we load them into another array called tickets. This array has two values to it, the user, and the ticket. So, up to know we have:
Ticket(0)="USER(0),3456"
Ticket(1)="USER(0),4321"
Ticket(2)="USER(0),8976"
After the second loop has finished, you can output the link as in:
Build a loop:
echo '<option value='Ticket(0)[0]'>'Ticket(0)[1]'</option>';
I found this most basic that describe in PHP. I am an ASP, VBA, and C++ guy. The theory is still the same!
$data = array();
while($row = mysql_fetch_assoc($result))
{
$data[$row['id']]['name'] = $row['name'];
// whatever else you want to do at this time....
}
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
149
Nov 12, 2018 at 07:01 PM
Nov 12, 2018 at 07:01 PM
Thanks ac3mark,
Your solution put me on to the correct track... I think. Im sure my code can be improved (a lot), but at least it works.
This is what I have ...
You now get a case of whatever beer/spirit you like. Thanks again for your time and advice. It is very much appreciated :^)
Your solution put me on to the correct track... I think. Im sure my code can be improved (a lot), but at least it works.
This is what I have ...
<?php
$data1 = "SELECT ID, Name, FROM Users
INNER JOIN Data
ON Data.Data_input_by=Users.ID
WHERE Data.id = $ticket_number";
$result1 = mysqli_query($conn, $data1);
$value1=mysqli_fetch_assoc($result1);
?>
<select name="tracking2" id="current_user2">
<?php
$data2 = "SELECT * FROM Users";
$result2 = mysqli_query($conn, $data2);
while($value2=mysqli_fetch_assoc($result2)) {
IF ($value1['ID'] != $value2['ID']) {
echo "<option value='{".$value2['ID']."}'>".$value2['Name']."</option>";
} ELSE {
echo "<option selected value='{".$value2['ID']."}'>".$value2['Name']."</option>";
}
}
?>
</select>
You now get a case of whatever beer/spirit you like. Thanks again for your time and advice. It is very much appreciated :^)
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
149
Nov 17, 2018 at 12:16 PM
Nov 17, 2018 at 12:16 PM
2 cases are on its way to my house. Get yourself round here before its gone!
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
149
Nov 27, 2018 at 03:44 PM
Nov 27, 2018 at 03:44 PM
mmmmm - nice this - I can see why you like it!
Oct 23, 2018 at 03:51 PM
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 :^)
Oct 25, 2018 at 09:38 AM
Updated on Oct 25, 2018 at 05:00 PM
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!