View Full Version : Random question time!
Infernette
11-11-2013, 07:09 PM
How do you get the name and the id of the creature to show in a drop down list? I can get one or the other to show, but not both. I used to know this but now I seemed to have forgot- It would be nice to know how to do it again, and even how to get it to show images would be awesome!
IntoRain
11-11-2013, 07:46 PM
Image I don't know if it's possible, but to add the code next to the name I don't really remember how I did it, but I believe I just went to the dropdown list creation and instead of sending just the name i send the code concatenated with the name, like:
$nameFinal = $name .= '( ' .= $code .= ')'
or something alike
edit:
I have this for females in the breeding thing
$index = 0;
foreach($femaleNames as $namesF){
//echo $femaleIDsarray[$index];
$equals = " (";
$equals2 = ")";
$nameAndID = $namesF .= $equals .= $femaleIDsarray[$index] .= $equals2;
//echo $nameAndID;
//echo $femaleIDsarray[$index];
$female->add(new Option($nameAndID, $femaleIDsarray[$index]));
$index++;
}
Infernette
11-11-2013, 08:27 PM
I can't seem to get it to work, I get this :
Adopt/Price:Cannot fill option objects inside this dropdownlist
As an error, code:
$ids = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' AND bred != 'comp' AND attached = 'no' and currentlevel > 6 and selling = 'no'")->fetchAll(PDO::FETCH_COLUMN);
$names1 = $mysidia->db->select("owned_adoptables", array("name"), "owner = '{$mysidia->user->username}' AND bred != 'comp' AND attached = 'no' and currentlevel > 6 and selling = 'no'")->fetchAll(PDO::FETCH_COLUMN);
$index = 0;
foreach($names1 as $names){
$equals = " (";
$equals2 = ")";
$nameFinal = $names .= $equals .= $ids[$index] .= $equals2;
$index++;
}
$adoptable->fill($nameFinal, $ids);
$chooseFrom->add($adoptable);
IntoRain
11-12-2013, 06:14 AM
I see, because you are using the fill function. In mine I add the options one by one to the dropdown list (called 'female'), so the left side is the field name and the right side the value. Try it like that?
Infernette
11-12-2013, 06:21 AM
I changed it to fill, but now it only shows one of the adoptables.
Updated code:
$ids = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' AND bred != 'comp' AND attached = 'no' and currentlevel > 6 and selling = 'no'")->fetchAll(PDO::FETCH_COLUMN);
$names1 = $mysidia->db->select("owned_adoptables", array("name"), "owner = '{$mysidia->user->username}' AND bred != 'comp' AND attached = 'no' and currentlevel > 6 and selling = 'no'")->fetchAll(PDO::FETCH_COLUMN);
$index = 0;
foreach($names1 as $names){
$equals = " (";
$equals2 = ")";
$nameFinal = $names .= $equals .= $ids[$index] .= $equals2;
$index++;
}
$adoptable->add(new Option($nameFinal, $ids[$index]));
$chooseFrom->add($adoptable);
IntoRain
11-12-2013, 06:25 AM
Oh, the add goes inside the the foreach cycle
Infernette
11-12-2013, 05:37 PM
Works now, awesome!
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.