Advertisement:

Select Box Issue

Aloittaja The Wizard, tammikuu 26, 2014, 06:38:56 AP

« edellinen - seuraava »

The Wizard

Hello:

I know this is a long shot, but I am hoping someone will find the flaw in the code below. I am trying to get the function getCatList() to work with the rest of the code, but no joy.

If it helps the function getCatList() is a select box and it does show up. The other part of the code displays images and data and that works too. The pagination works as well. The problem is when I choose a item form the select box the system goes through the motions correctly, but I still see all the images and data and not what I choose from the select box.

Thanks

Wiz



function ShopInv() // Your Toy Room
{
global $context, $scripturl, $txt, $smcFunc, $modSettings, $user_info;

loadTemplate('WizardsShopUser');
loadLanguage('WizardsShop');
formatMoney($money);

// Page title for the main page
$context['page_title'] = $txt['shop_inv_page_title'];

// Navigational link tree to be shown at the top of the page.
$context['linktree'][] = array(
'url' => $scripturl . '?action=shop_inv',
'name' => $txt['shop_inv']
);

// Title Text
$context['shop_inv_Head'] = $txt['wizards_shop_inv'];

// Get an array of all the categories
function getCatList()
{
global $smcFunc;

// Start with an empty array
$cats = array();

// Get all the categories
$result = $smcFunc['db_query']('', "
SELECT id, name, count
FROM {db_prefix}shop_categories
ORDER BY name ASC", array());

// Loop through all the categories
while ($row = $smcFunc['db_fetch_assoc']($result))
{
// Let's add this to our array
$cats[] = array(
'id' => $row['id'],
'name' => $row['name'],
'count' => $row['count']
);
}

$smcFunc['db_free_result']($result);

// Return the array
return $cats;
}

// If the sort method isn't defined, assume a default
if (!isset($_GET['sort']))
$_GET['sort'] = '0';
if (!isset($_GET['sortDir']))
$_GET['sortDir'] = '0';

// Get the sort type
switch ($_GET['sort'])
{
case 0:
$context['shop_inv']['sort_type'] = $txt['wizards_shop_name'];
$sortQuery = 'name';
break;
case 1:
$context['shop_inv']['sort_type'] = $txt['wizards_shop_price'];
$sortQuery = 'price';
break;
case 2:
$context['shop_inv']['sort_type'] = $txt['wizards_shop_description'];
$sortQuery = '`desc`';
break;
case 3:
$context['shop_inv']['sort_type'] = $txt['wizards_shop_stock'];
$sortQuery = 'stock';
break;
default:
fatal_error($txt['wizards_shop_invalid_sort']);
break;
}

// And the direction
switch ($_GET['sortDir'])
{
case 0:
$context['shop_inv']['sort_dir'] = $txt['wizards_shop_asc'];
$sortDirQuery = 'ASC';
break;
case 1:
$context['shop_inv']['sort_dir'] = $txt['wizards_shop_desc'];
$sortDirQuery = 'DESC';
break;
default:
fatal_error($txt['wizards_shop_invalid_sort_direction']);
break;
}

// Are we only displaying a certain category?
if (isset($_GET['cat']) && $_GET['cat'] != -1)
{
$context['shop_inv']['category'] = (int) $_GET['cat'];
$catClause = 'WHERE category = ' . $context['shop_inv']['category'];
}
else
{
$context['shop_inv']['category'] = -1;
$catClause = '';
}

// List of all categories
$context['shop_inv']['categories'] = getCatList();

// Viewing your inventory

// Get the number of items available
$result = $smcFunc['db_query']('', "
SELECT COUNT(id)
FROM {db_prefix}shop_inventory
WHERE ownerid = {int:id}", array(
'id' => $user_info['id']
));
list($context['shop_inv']['item_count']) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);

// If the page is not set, assume page 1
if (!isset($_GET['page']))
$_GET['page'] = 1;
// If items per page not set, assume 15
if (!isset($modSettings['shopItemsPerPage']))
$modSettings['shopItemsPerPage'] = 15;

// The page count - Total number of items divided by number per page
$context['shop_inv']['pages']['total'] = ceil($context['shop_inv']['item_count'] / $modSettings['shopItemsPerPage']);
// First item
$firstItem = ($_GET['page'] * $modSettings['shopItemsPerPage']) - $modSettings['shopItemsPerPage'];

// Start with empty items array
$context['shop_inv']['items'] = array();

// Get all the inventory items on current page
$result = $smcFunc['db_query']('', "
SELECT it.name, it.desc, it.input_needed, it.can_use_item, it.image,
inv.amtpaid, inv.id, inv.trading, inv.tradecost
FROM {db_prefix}shop_inventory AS inv, {db_prefix}shop_items AS it
WHERE inv.ownerid = {int:ownerid} AND inv.itemid = it.id
ORDER BY it.can_use_item DESC, it.name ASC, inv.id ASC
LIMIT {int:firstitem}, {int:itemsperpage}", array(
'ownerid' => $user_info['id'],
'firstitem' => $firstItem,
'itemsperpage' => $modSettings['shopItemsPerPage']
));

// Loop through results
while ($row = $smcFunc['db_fetch_assoc']($result))
$context['shop_inv']['items'][] = array(
'id' => $row['id'],
'image' => $row['image'],
'name' => $row['name'],
'desc' => $row['desc'],
'amtpaid' => $row['amtpaid'],
'can_use_item' => $row['can_use_item'],
'input_needed' => $row['input_needed'],
'trading' => $row['trading'],
'tradecost' => $row['tradecost']
);
$smcFunc['db_free_result']($result);

// Miscellaneous stuff
$context['shop_inv']['pages']['current'] = $smcFunc['htmlspecialchars']($_GET['page']);

$context['shop_inv']['pages']['link'] = $scripturl . '?action=shop_inv;sort=' . $_GET['sort'] . ';sortDir=' . $_GET['sortDir'];
if (isset($context['shop_inv']['category']))
$context['shop_inv']['pages']['link'] .= ';cat=' . $context['shop_inv']['category'];

// Set some miscellaneous variables
$context['shop_links_categories'] = 10;
$context['shop_link_value'] = 'shop_inv';

// Use the shopinv template
$context['sub_template'] = 'shopinv';
}

SoLoGHoST

First off, your question is incomplete.  How are we supposed to help you if we don't see what is happening in the HTML part of the code (template) with these $context variables.  2nd, Looks like you are using a mod, perhaps you can ask over in the Mod support topic?  Or tell us the name of the mod with a link to where it can be found.  Or am I wrong in assuming that this is not your own mod?  3rd - How can a function in PHP be a select box without any HTML behind it?  4th - Why are you putting functions inside of functions?  There is nothing wrong with it, but it just makes it harder to read and understand.

Advertisement: