So I have been searching and doing trial and error for several days now, and Im turning to here for help.
I have created a page on my website that pulls a schedule information from a table on a database and displays it to the webpage. I am trying to pull a color scheme from a second table in the same DB, when the name on the first table matches the name on the second table, only that name will be displayed in the different color assigned to it. MY tables look as follows:
Schedule:
id time timeframe Monday Tuesday Wednesday Thursday Friday Saturday Sunday 1 12a 00:00:00 Name1 Name2 Name3 Name2 Name5 Name6 Name7 2 1a 01:00:00 Name1 Name2 Name3 Name2 Name5 Name4 Name3 3 2a 02:00:00 Name1 Name2 Name4 Name2 Name2 Name6 Name2 4 3a 03:00:00 Name2 Name2 Name4 Name2 Name3 Name3 Name2
ect.
dj_colors:
TBL2: id name color 1 Name1 #hexcolor 2 Name2 #hexcolor2 3 Name3 #hexcolor3 ect
$query = array('select' => "*",
'tbl' => "Schedule");
$name = "select t1.*, Monday.color, Tuesday.color, Wednesday.color, Thursday.color, Friday.color, Saturday.color, Sunday.color
FROM Schedule t1
JOIN dj_colors Monday
ON t1.Monday = Monday.name,
JOIN dj_colors Tuesday
ON t1.Tuesday = Tuesday.name,
JOIN dj_colors Wednesday
ON t1.Wednesday = Wednesday.name,
JOIN dj_colors Thursday
ON t1.Thursday = Thursday.name,
JOIN dj_colors Friday
ON t1.Friday = Friday.name,
JOIN dj_colors Saturday
ON t1.Saturday = Saturday.name,
JOIN dj_colors Sunday
ON t1.Sunday = Sunday.name";
$DB = new DB();
$result = $DB->select_multi($query);
foreach ($result as $arrayLoop) {
$printout .= "<tr>";
foreach ($arrayLoop as $field => $data) {
if ($field == 'id' || $field == 'TimeFrame') continue;
if ($data === $name) $printout .= "<td color=".$color.">".$data."</td>";
else $printout .= "<td class='schedule4'>".$data."</td>";
}
$printout .= "</tr>";
}
I am pulling names from the Schedule db and posting them to a website. That part works fine. I am also trying to make it to where if the name in the field from db Schedule matches the name on db dj_colors, that name will be displayed in the color assigned to that name in dj_colors. I am at a loss here (I am still new to php coding and just learning the JOIN function). I am not wanting anyone to do it for me, but point me in the right direction anf give me some helpful pointers on where I am going wrong, please.