Hi Ragi,
> With the current dropdown, only the last message is displayed.
- This is because we're only getting one record as per this line:
$latestNewsletter = @$_nlb_messages[0]; // get first record
To display all the messages under the selected newsletter, you should loop through $_nlb_messages and display each record. Displaying the $latestNewsletter record will only display the latest record.
If you need a second dropdown for selecting which message to display, loop through $_nlb_messages and display each as <option> of a drop down select field. For example:
<?php if ($_nlb_messages): ?>
<select name="message_num">
<option value="">--</option>
<?php foreach($_nlb_messages as $message): ?>
<option value="<?php echo htmlencode($message['num']); ?>" <?php selectedIf($message['num'], @$_REQUEST['message_num']); ?>>
<?php echo htmlencode($message['subject']); ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>
And then add another clause to your 'where' statement to filter the results by 'num' of the selected message. For example:
$whereMessageNumIs = 'TRUE';
if (@$_REQUEST['message_num']){
$whereMessageNumIs = " num = '".mysql_escape($_REQUEST['message_num'])."'";
}
list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
'tableName' => '_nlb_messages',
//...
'where' => "to_list = '" . coalesce(mysql_escape(@$_REQUEST['to_list']), '2') . "' AND " . $whereMessageNumIs,
));
For readability, you might want to add the to_list filter to a where variable as well. For example:
$where = 'TRUE';
if (@$_REQUEST['to_list']){
$where .= " AND to_list = '".mysql_escape($_REQUEST['to_list'])."'";
}
if (@$_REQUEST['message_num']){
$where .= " AND num = '".mysql_escape($_REQUEST['message_num'])."'";
}
list($_nlb_messages, $_nlb_messagesMetaData) = getRecords(array(
'tableName' => '_nlb_messages',
//...
'where' => $where,
));
Cheers,
Daryl Maximo
PHP Programmer - interactivetools.com