How to join 2 tables and fetch name from one?

Forum
Last Post
Threads / Messages

KittHaven

Member
Member
Joined
May 21, 2013
Messages
478
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,292
Hi! I have a colour palette on my site and on the custom pet screen I display what the current selected colour is for the various parts. That works well but I'd like to display the hex name from the adopts_colour_palette table instead of just the hex value from the adopts_custom table.

2023-07-11 16_03_05-Bean Pets and 8 more pages - Personal - Microsoft​ Edge.png

You can see that all the colours have the hex and then their name next to them, but the top option (the current registered value in the DB) is just the hex. I'm not sure how to join the customs table (which stores the hex of each colour) and the colour_palette table (which stored both hex and name) to fetch the colour name depending on what the current hex is.

Currently this is how I get the selected colours:

PHP:
$selected = $mysidia->db->select("custom", array(), "uid='{$mysidia->user->getID()}' && species='cat_bean'")->fetchObject();

Then to fetch it for each specific dropdown (there are lots of customisation options so there are a few lol) I use:

PHP:
{$selected->body_colour1},
{$selected->nose_colour}, etc

I know you can use something like this:

PHP:
$body_colour1 = $mysidia->db->join("custom", "{$selected->body_colour1}.hex = colour_palette.hex")
                              ->select("colour_palette", [], "");

But I'm unsure how to finish it. I also assume you'd need to repeat it for each instance you want to fetch, like body_colour1, body_colour2, etc. But if I'm wrong about that and there is a way to do it without needing like 20 lines of code then I'm all ears lol

Thanks~
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,122
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top