wpeloquin
02-03-2011, 07:12 PM
To start, yes I am a novice at this and am currently learning.
I am having difficulty getting a single array to work in multiple places. i have a table with a list of classes in it, and i pull that into an array. i then want to use the data in that array to make multiple <select> form options. This code that i have works with one <select> but leaves the others blank. If i make 3 arrays, one for each, then it all works. Is it not possible to use just 1 array to knock out some of the redundancy of the code?
here is the code:
$my_classall = $vbulletin->db->query_read("
SELECT class_id, class_name
FROM " . TABLE_PREFIX . "my_table_class AS my_table_class
ORDER BY class_name ASC
");
while ($my_class1 = $vbulletin->db->fetch_array($my_classall))
{
$my_class1_name = $my_class1['class_name'];
eval('$my_class1selector .= " <option value=\"'.$my_class1['class_id'].'\" " . iif($my_toon[class_1]==$my_class1[class_id]," selected=\"selected\"","").">'.htmlspecialchars($my_class1['class_name']).'</option> ";');
}
while ($my_class2 = $vbulletin->db->fetch_array($my_classall))
{
$my_class2_name = $my_class2['class_name'];
eval('$my_class2selector .= " <option value=\"'.$my_class2['class_id'].'\" " . iif($my_toon[class_2]==$my_class2[class_id]," selected=\"selected\"","").">'.htmlspecialchars($my_class2['class_name']).'</option> ";');
}
I am having difficulty getting a single array to work in multiple places. i have a table with a list of classes in it, and i pull that into an array. i then want to use the data in that array to make multiple <select> form options. This code that i have works with one <select> but leaves the others blank. If i make 3 arrays, one for each, then it all works. Is it not possible to use just 1 array to knock out some of the redundancy of the code?
here is the code:
$my_classall = $vbulletin->db->query_read("
SELECT class_id, class_name
FROM " . TABLE_PREFIX . "my_table_class AS my_table_class
ORDER BY class_name ASC
");
while ($my_class1 = $vbulletin->db->fetch_array($my_classall))
{
$my_class1_name = $my_class1['class_name'];
eval('$my_class1selector .= " <option value=\"'.$my_class1['class_id'].'\" " . iif($my_toon[class_1]==$my_class1[class_id]," selected=\"selected\"","").">'.htmlspecialchars($my_class1['class_name']).'</option> ";');
}
while ($my_class2 = $vbulletin->db->fetch_array($my_classall))
{
$my_class2_name = $my_class2['class_name'];
eval('$my_class2selector .= " <option value=\"'.$my_class2['class_id'].'\" " . iif($my_toon[class_2]==$my_class2[class_id]," selected=\"selected\"","").">'.htmlspecialchars($my_class2['class_name']).'</option> ";');
}