This is a generic problem I'm having but an example is below. What I'm trying to do is get the data from the database (using model classes) and pass the data via an array to the view classes (via controller classes if any processing of the data needs to be done).
The example below works fine when dealing with the data in the model class but whatever I've tried so far either results in the display of only one line of the array or a line of the array still displays but it keeps on repeating until php times out.
I'm trying to keep the model classes solely for accessing and interfacing with the data with the controllers only processing the data and the views only displaying the data (with a minor bit of processing to decide what needs viewing).
I'm trying to always use while loops over foreach loops wherever possible due to the superior performance of while loops.
As i'm still relavtivly new to OOP php, my suspision is that i don't know the proper syntax for what i'm trying to do.
method from messages_model class
Method from messages_view classPHP Code:function message_inbox_get_messages($db,$user_id) {
$sql="SELECT
ue_messages_delivery.message_id AS message_id,
ue_messages_delivery.sender_id AS sender_id,
ue_messages.subject AS subject,
ue_messages_delivery.date_sent AS date_sent
FROM ue_messages
INNER JOIN ue_messages_delivery
ON ue_messages.message_id = ue_messages_delivery.message_id
WHERE ue_messages_delivery.recipient_id = '$user_id'
AND ue_messages_delivery.parent_id = 0 ";
$result=$db->dbQuery($sql);
while ( $row=$db->dbFetchArray($result) ) {
$sent_by=$row['sender_id'];
$message_id=$row['message_id'];
$subject=$row['subject'];
$from_user=$this->messages_get_sender_name($sent_by,$db);
echo "<tr>\n";
echo "<td>" .$from_user."</td>\n";
echo "<td>link for selecting a message to view</td>\n";
echo "<td>" .$row['date_sent']."</td>\n";
echo "</tr>\n";
$message['message_id']=$row['message_id'];
$message['date_sent']=$row['date_sent'];
}
}
PHP Code:function display_inbox($db) {
$user_id=4;
echo "<h1>View Inbox</h1>";
echo "<table class='all_messages'>\n";
echo "<tr>";
echo " <th>";
echo ' From';
echo " </th>\n";
echo " <th>";
echo ' Subject';
echo " </th>\n";
echo " <th>";
echo ' Time';
echo " </th>\n";
echo "</tr>";
$num_messages=$this->messages_model->messages_count($db);
if ( $num_messages < 1 ) {
echo "<tr>";
echo "<td colspan='4'>";
echo "<div class='no_news'>No messages in your inbox</div>";
echo "</td>";
echo "</tr>";
} else {
$this->messages_model->message_inbox_get_messages($db,$user_id);
}
echo "</table>\n";
echo "<div class='button'><p><a href='main_page.php?view=messages&subview=write_message'>Write New Message</a></p></div>\n";
}







Bookmarks