Let's break it down:```
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
The above is used within page modules in order to load language files relevant to the page being referenced at runtime ... ie: the result of $_GET['main_page']
$breadcrumb->add(NAVBAR_TITLE);
$products_new_array = array();
--------------------------
All the above are not needed if this is to be run in a function
--------------------------
$products_new_query_raw = "SELECT products_id
FROM " . TABLE_PRODUCTS . " p
WHERE products_status = 1 ";
$products_new_query_raw = $db->bindVars($products_new_query_raw, ':languageID', $_SESSION['languages_id'], 'integer');
It would normally be used to sanitize the SQL query and ensure that the value passed for language id was truly an integer before getting to the database. Basically, binding data-types in the query, enforcing proper use, largely to prevent injection risks
$check_products_all = $db->Execute($products_new_query_raw);
$array_ids = array();
while (!$check_products_all->EOF)
{
array_push($array_ids,$check_products_all->fields['products_id']);
A faster approach would be this simpler line:```
$array_ids[] = $check_products_all->fields['products_id'];
$check_products_all->MoveNext();
}
```MoveNext continues the while loop ... which ends when the end of the retrieved records is reached.
If you wanted to convert this all to a function, you'd need to reference the $db object as a global -- otherwise your database connection details are unreachable within the local scope of your function.
ie:
function my_get_all_product_ids() {
global $db;
$products_new_query_raw = "SELECT products_id
FROM " . TABLE_PRODUCTS . " p
WHERE products_status = 1 ";
$check_products_all = $db->Execute($products_new_query_raw);
$array_ids = array();
while (!$check_products_all->EOF)
{
$array_ids[] = $check_products_all->fields['products_id'];
$check_products_all->MoveNext();
}
return $array_ids;
}
Proof of concept:
- upload the above code by inserting it in a file in the extra_functions folder
- run this from somewhere on your site:```
$var1 = my_get_all_product_ids();
echo '<pre>';
print_r($var1);
echo '</pre>';
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.