Benumbed
02-22-2005, 06:00 AM
I am doing a modified version of makechoosercode, where it gets the entry's in table "dkp_items".
// ###################### Start makechoosercode #######################
function print_chooser_row3($title, $name, $tablename, $selvalue = -1, $extra = '', $size = 0, $wherecondition = '')
{
// returns a combo box containing a list of titles in the $tablename table.
// allows specification of selected value in $selvalue
// checks for existence of $iusergroupcache / $iforumcache etc first...
global $DB_site;
$tableid = 'item_id';
$cachename = 'i' . $tablename . 'cache_' . md5($wherecondition);
if (!is_array($GLOBALS["$cachename"]))
{
$GLOBALS["$cachename"] = array();
$result = $DB_site->query("SELECT item_name, $tableid FROM " . TABLE_PREFIX . "$tablename $wherecondition ORDER BY item_name");
while ($currow = $DB_site->fetch_array($result))
{
$GLOBALS["$cachename"]["$currow[$tableid]"] = $currow['item_name'];
}
unset($currow);
$DB_site->free_result($result);
}
$selectoptions = array();
if ($extra)
{
$selectoptions['-1'] = $extra;
}
foreach ($GLOBALS["$cachename"] AS $nowitemid => $itemtitle)
{
$selectoptions["$nowitemid"] = $itemtitle;
}
print_select_row($title, $name, $selectoptions, $selvalue, 0, $size);
}
There will be some items that are in there more than once, will have different item_id's of course. How would I go about modifying that code to where it does not display an itemname more than once.
What happens is this:
When someone adds an item into the database, it adds who bought it, item name, date it was bought etc. So, in other words...someone could have bought the item twice or more than one person could have bought the same item.
When I am adding this in thru a file, I have a drop down of all items bought (this is where the dupes are), and a field to add a new item.
// ###################### Start makechoosercode #######################
function print_chooser_row3($title, $name, $tablename, $selvalue = -1, $extra = '', $size = 0, $wherecondition = '')
{
// returns a combo box containing a list of titles in the $tablename table.
// allows specification of selected value in $selvalue
// checks for existence of $iusergroupcache / $iforumcache etc first...
global $DB_site;
$tableid = 'item_id';
$cachename = 'i' . $tablename . 'cache_' . md5($wherecondition);
if (!is_array($GLOBALS["$cachename"]))
{
$GLOBALS["$cachename"] = array();
$result = $DB_site->query("SELECT item_name, $tableid FROM " . TABLE_PREFIX . "$tablename $wherecondition ORDER BY item_name");
while ($currow = $DB_site->fetch_array($result))
{
$GLOBALS["$cachename"]["$currow[$tableid]"] = $currow['item_name'];
}
unset($currow);
$DB_site->free_result($result);
}
$selectoptions = array();
if ($extra)
{
$selectoptions['-1'] = $extra;
}
foreach ($GLOBALS["$cachename"] AS $nowitemid => $itemtitle)
{
$selectoptions["$nowitemid"] = $itemtitle;
}
print_select_row($title, $name, $selectoptions, $selvalue, 0, $size);
}
There will be some items that are in there more than once, will have different item_id's of course. How would I go about modifying that code to where it does not display an itemname more than once.
What happens is this:
When someone adds an item into the database, it adds who bought it, item name, date it was bought etc. So, in other words...someone could have bought the item twice or more than one person could have bought the same item.
When I am adding this in thru a file, I have a drop down of all items bought (this is where the dupes are), and a field to add a new item.