I know this question has been asked multiple times on here but each one is a little different.
I have a table in my database with the columns entry_id(INT- Auto_Increment), user_id(INT), firstname(VARCHAR), lastname(VARCHAR) and comment(VARCHAR).
My script is pretty much a very basic timesheet I have tried creating, the user_id, firstname and lastnames are set when the user visits the script. So what I need to do is check the last comment cell for that user to see if the comment is either "in" or "out".
Whenever I try building my query and checking if the last comment in that users field is either in or out, I visit my script and it doesn't print the comment, what am I doing wrong?
$userid = $_SESSION['user_id'];
$query = mysqli_query($mysqli, "SELECT entry_id, user_id FROM timesheet WHERE user_id = '$userid' ORDER BY entry_id DESC LIMIT 1") or die('Error: ' . mysqli_error($mysqli));
if(mysqli_num_rows($query)>0){
while ($row = mysqli_fetch_array($query, MYSQL_ASSOC)) {
echo '<pre>';
print_r($row);
echo '</pre>';
$clock = $row['comment'];
echo $clock . ' Last entry';
}
Couple of notes:
I AM connected to the database and get a simple query to work. The userid session is set. Prior to asking this question I looked at the answers here and here.
Here is what $row is printing, notice how comment is empty although I know I have a value in the database.
Array
(
[entry_id] => 4
[user_id] => 3
[comment] =>
)
$row['comment']. Where is that supposed to come from? The only keys in$rowwill be the fields you queried.error_reporting(E_ALL); ini_set('display_errors', '1');