General Community > Scripting Help


(1/2) > >>

Hi, i'm making a User Control Panel for a project of mine, I am wondering how I could make a selection list with colours in them but the colours which are being used already wont show. When someone gets a colour it's saved into a MySQL row like this "FFFFFF", how can I check to see if that colour has already been taken?

I can help you write something in PHP for this. Is this an addon for SMF or just a completely separate script?

It's a seperate script.

So you have a list (array) of possible colors (let's call it $colors) and a database table which includes used_color for each user. You want to build a selection list of all the colors in $colors that are not found in used_color? I would start by building an array of all used colors, taken by reading used_color in the table. Call it $used_colors. You're going to have to loop through the $colors list one by one anyway to build each <option> tag, so take that opportunity to check if that $colors[$i] element is found in the $used_colors array:

--- Code: ---...output <select> tag...
for ($i=0; $i<count($colors); $i++) {
   if (!in_array($colors[$i], $used_colors)) {
      ... output <option> tag for selection list with $colors[$i] and the associated name ...
... output </select> tag ...
--- End code ---

So, i'd query the table row which stores the colours and do something like this;

--- Code: ---$row['Colour'] = array();

--- End code ---
and then loop it?


[0] Message Index

[#] Next page

Go to full version