General Community > Scripting Help
MySQL & PHP
MrPhil:
No, it would be more like
--- Code: ---$used_colours = array();
$results = mysql_query("SELECT colour FROM whatever table");
loop until $results exhausted, putting into $row array
$used_colours[] = $row['colour']; // assumes used colours are unique
end loop
--- End code ---
There are plenty of places in SMF to copy the code from and adjust to your needs. Then once you have the $used_colors array, use the code from my previous post, which assumes you built an array of $colours at some point.
That's just one way of doing it. If you ask half a dozen programmers how to do it, you'll get back as many as six somewhat different methods.
Luis-:
Here's my code so far, it's still not working and I have no idea since I haven't worked with arrays before.
--- Code: ---<?php
$colors = array(
"FFFFFF",
"00FFFF",
"B8860B"
);
$used_colours = array();
$results = mysql_query("SELECT Colour FROM airlines ORDER BY `airlines`.`ID` ASC LIMIT 0, 30");
while($row = mysql_fetch_assoc($results)) {
$used_colours[] = $row['Colour'];
}
?> <select size="1"> <?php
for ($i=0; $i<count($colors); $i++) {
if (!in_array($colors[$i], $used_colors)) {
?><option value=<?php echo $colors[$i]; ?>"><?php echo $colors[$i]; ?></option><?php
}
}
?></select>
--- End code ---
Colin:
Are you getting some sort of error?
Luis-:
No, it's just showing all of the colours in the $colors array but one of the users in my table is already using it, yet it's still showing.
MrPhil:
You've got to decide on a consistent spelling for $colors/$colours and $used_colors/$used_colours.
Navigation
[0] Message Index
[*] Previous page
Go to full version