
Имя и должность заемщика не отображаются как и ожидалось в моем приложении CodeIgniter 4. Несмотря на попытки различных решений, проблема остается. Может ли кто-нибудь помочь устранить неполадку и решить ее? Будем очень признательны за вашу помощь.
public function getPendingTransactions($user_id = null)
{
// Start the query builder
$builder = $this->db->table('transactions')
->select([
'transactions.transaction_id',
'transactions.user_id',
'transactions.book_id',
'transactions.borrow_date',
'transactions.due_date',
'transactions.status',
'users.firstname',
'users.lastname',
'books.title'
])
->join('users', 'users.user_id = transactions.user_id', 'left') // Left join for users
->join('books', 'books.book_id = transactions.book_id', 'left') // Left join for books
->where('transactions.status', 'pending'); // Filter by pending status
// Add user filter if provided
if ($user_id !== null) {
$builder->where('transactions.user_id', $user_id);
}
// Debug: Log the compiled SQL query
log_message('debug', 'SQL Query: ' . $builder->getCompiledSelect());
// Fetch the transactions
$transactions = $builder->get()->getResultArray();
// Log the query result for debugging
log_message('debug', 'Pending Transactions Query Result: ' . print_r($transactions, true));
// Handle NULL values by setting defaults
foreach ($transactions as &$transaction) {
// Default to 'Unknown' for firstname, 'N/A' for title, and empty string for lastname
$transaction['firstname'] = !empty($transaction['firstname']) ? $transaction['firstname'] : 'Unknown';
$transaction['lastname'] = !empty($transaction['lastname']) ? $transaction['lastname'] : '';
$transaction['title'] = !empty($transaction['title']) ? $transaction['title'] : 'N/A';
}
return $transactions;
}
public function showPendingTransactions($user_id = null)
{
$pendingTransactions = $this->getPendingTransactions($user_id);
if (empty($pendingTransactions)) {
log_message('debug', 'No pending transactions found.');
} else {
log_message('debug', 'Pending Transactions: ' . print_r($pendingTransactions, true));
}
return view('admin/approve_reject_transactions', ['pendingTransactions' => $pendingTransactions]);
}
Approve or Reject Transactions
body {
font-family: Arial, sans-serif;
background-color: #f4f7fc;
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: 20px auto;
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.alert {
padding: 15px;
margin-bottom: 20px;
background-color: #4CAF50;
color: white;
border-radius: 5px;
}
.table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.table th, .table td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}
.table th {
background-color: #007BFF;
color: white;
}
.table tr:nth-child(even) {
background-color: #f2f2f2;
}
.btn {
padding: 8px 16px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
cursor: pointer;
border-radius: 4px;
}
.btn-success {
background-color: #28a745;
color: white;
border: none;
}
.btn-danger {
background-color: #dc3545;
color: white;
border: none;
}
.btn:hover {
opacity: 0.8;
}
form input[type="date"] {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
form button {
margin-left: 10px;
}
.actions {
display: flex;
justify-content: space-around;
align-items: center;
}
.actions form {
margin-right: 10px;
}
Pending Borrowed Books
Transaction ID
Borrower Name
Book Title
Borrowed Date
Due Date
Status
Actions
Подробнее здесь: https://stackoverflow.com/questions/791 ... -title-fro