//Get column names $c = $dbh->prepare("DESCRIBE cm_journals"); $c->execute(); $cols = $c->fetchAll(PDO::FETCH_COLUMN); //Get output $q = $dbh->prepare($sql); $q->execute(); $error = $q->errorInfo(); while ($result = $q->fetch(PDO::FETCH_ASSOC)) { $rows = array(); //Add user picture $pic = "<img class='thumbnail-mask' src='" . return_thumbnail($dbh, $result['username']) . "' border='0'>"; $rows[] = $pic; //Format data $result['username'] = username_to_fullname($dbh, $result['username']); $result['date_added'] = extract_date_time_sortable($result['date_added']); //Check to see if this user has read or archived this journal if (in_string($user, $result['read'])) { $result['read'] = 'yes'; } else { $result['read'] = ''; } if (in_string($user, $result['archived'])) { $result['archived'] = 'yes'; } else { $result['archived'] = ''; } foreach ($cols as $col) { $rows[] = $result[$col]; } $output['aaData'][] = $rows;
$group_name_data = group_display_name_array($dbh); //Get array of supervisor names. Again, avoids excessive db calls $supervisor_name_data = supervisor_names_array($dbh); $cols = implode(', ', $columns); $q = $dbh->prepare("SELECT {$cols} FROM `cm_users` WHERE supervisors LIKE '{$user},%'\n\t\t\tOR supervisors LIKE '%,{$user},%'"); $q->execute(); while ($result = $q->fetch(PDO::FETCH_ASSOC)) { $rows = array(); foreach ($columns as $col) { if ($col === 'picture_url') { $th = thumbify($result[$col]); $rows[] = "<img class='thumbnail-mask' src = '" . $th . "?" . rand() . "'></img>"; } elseif ($col === 'email') { $rows[] = "<a href='mailto:" . $result[$col] . "' target='_new'>" . $result[$col] . "</a>"; } elseif ($col === 'date_created') { $rows[] = extract_date_time_sortable($result[$col]); } elseif ($col === 'grp') { $rows[] = array_search($result[$col], $group_name_data); } elseif ($col === 'supervisors') { if (!empty($result[$col])) { $sups = explode(',', $result[$col]); $sup_names = array(); foreach ($sups as $sup) { $sup_names[] = array_search($sup, $supervisor_name_data); } $rows[] = rtrim(implode(', ', $sup_names), ', '); } else { $rows[] = ''; } } else { $rows[] = $result[$col];