As the topic suggests, I'm trying to populate a drop down box with content from my database.
So far I've been studying the create_account page and implemented the following code changes.
The following code has been added to the page where I would like the drop down box to appear.
PHP Code:
<fieldset>
<label class="inputLabel" for="referral"><?php echo ENTRY_REFERRAL; ?></label>
<?php echo zen_get_referral_list('referral_id', '0', 'id="referral"') . (zen_not_null(ENTRY_REFERRAL_TEXT) ? '<span class="alert">' . ENTRY_REFERRAL_TEXT . '</span>': ''); ?>
</fieldset>
I have also created a couple of new functions (by editing the country code used on the create_account page). This should enable me to pull any data I wish from the database.
PHP Code:
/*
* Creates a pull-down list of countries
*/
function zen_get_referral_list($name, $selected = '', $parameters = '') {
$countries_array = array(array('id' => '', 'text' => PLEASE_SELECT));
$countries = zen_get_referrals();
for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
$countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
}
return zen_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
}
////
// Returns an array with countries
// TABLES: countries
function zen_get_referrals($default = '') {
global $db;
$countries_array = array();
if ($default) {
$countries_array[] = array('id' => '',
'text' => $default);
}
$countries = $db->Execute("select countries_id, countries_name
from " . TABLE_COUNTRIES . "
order by countries_name");
while (!$countries->EOF) {
$countries_array[] = array('id' => $countries->fields['countries_id'],
'text' => $countries->fields['countries_name']);
$countries->MoveNext();
}
return $countries_array;
}
While testing this method, as some of you may notice, I have merely renamed the two functions above and not made any changes to the type of data they are pulling from the database.
However, when I changed the following line of code (from function zen_get_referral_list) it stopped working!
From:
Code:
$countries = zen_get_countries();
To:
Code:
$countries = zen_get_referrals();
Obviously I've not successfully replicated all of the required code, which explains why things are not working.
Does anyone (maybe one of the Zen Cart Devs) know how I can resolve this?
I've been looking at this all day and, while I've learnt a lot more about how Zen Cart works I cannot fix this!
Thanks in advance,
Alex