我在文档加载时隐藏了一个表行。我有 foreach 运行,它从我指定的数据库中收集值。以下是从DB检索的数据的示例。我想加载产品数据,其中每个产品的自定义字段值等于其中一个下拉选项。
我有这段代码(这个表有大约8列,但我只选择了一个来显示该过程如何工作):
<select id="tempdropdown">
<option value="frozen">Frozen</option>
<option value="other">Other</option>
</select>
<td style="padding-right: 15px;"><?php
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('customfield_value', 'virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db->quote('6'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' . $db->quote($product->virtuemart_product_id));
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadResult();
echo ($results);
?>
</td>
我需要做这样的事情(我真的希望它有意义):
<?php
// Start the Output
foreach ( $this->products as $product ) {
// Show the horizontal seperator
if ($iBrowseCol == 1 && $iBrowseProduct > $BrowseProducts_per_row) { ?>
<div class="horizontal-separator"></div>
<?php }
?>
<tr style="border-bottom: 1px solid #ffb3b3; height: 30px; display:;">
<!-- All products are loaded in this row. Products are hidden on load. I will show an example of a <td> which retrieves
data from the DB -->
<!-- I LOADED THE DATA USING THE FIRST PIECE OF CODE IN THE POST. THIS LOADS THE FIELDS FOR THE PRODUCTS -->
<!-- I need to load this data based on the dropdown selection. There is a customfield "Temp Zone". All the products have
either "Frozen" or "Other" as this customfield value. -->
<td style="width: 80px;text-align: center;">
<?php
$dropdown = ('#dropdown');
// Get a db connection.
$db = JFactory::getDbo();
$valueTEMP = ('SELECT customfield_value, virtuemart_product_id, customfield_id FROM jos_virtuemart_product_customfields WHERE customfield_id["21"] == ''Frozen');
// Create a new query object.
$query = $db->getQuery(true);
if($dropdown == "Frozen" && $valueTEMP == True) {
$query->select($db->quoteName(array('customfield_value', 'virtuemart_product_id', 'customfield_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db->quote('21'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' . $db->quote($product->virtuemart_product_id));
}
else {
$query->select($db->quoteName(array('customfield_value', 'virtuemart_product_id', 'customfield_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db->quote('21'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' . $db->quote($product->virtuemart_product_id));
}
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadResult();
echo ($results);
?>
</td>
</tr>
<?php }
} // end of foreach ( $this->products as $product )
?>
</table>
我不介意在每一段代码中都有这个,如果它可以以某种方式工作。目前,我不知道如何在满足特定条件时告诉系统检索所有产品数据。但是,如果我必须手动编辑每个代码所在的位置并为每个代码设置条件,我根本不介意。