Jump to content

Recommended Posts

Posted (edited)

Php Experts,

I need to fetch not the last row in the table but the last entry based on a condition. I only know how to fetch the last row in the table. 

I tried coding the way I think it is done but no luck. Googled but no luck. 

$query_for_today_date_and_time = "SELECT date_and_time FROM logins WHERE username = ? ORDER BY id DESC LIMIT 1"; 
        if($stmt_for_today_date_and_time = mysqli_prepare($conn,$query_for_today_date_and_time)) 
        { 
            mysqli_stmt_bind_param($stmt_for_today_date_and_time,'s',$db_username); 
            mysqli_stmt_execute($stmt_for_today_date_and_time); 
            $result_for_today_date_and_time = mysqli_stmt_bind_result($stmt_for_today_date_and_time,$db_today_date_and_time); 
            mysqli_stmt_fetch($stmt_for_today_date_and_time); 
            
            $today_date_and_time = $db_today_date_and_time; 
            mysqli_stmt_close($stmt_for_today_date_and_time); 
        } 
        else 
        { 
            mysqli_stmt_close($stmt_for_today_date_and_time); 
        
            mysqli_close($conn); 
        
            die("<h1 style=\"font-family:courier; color:red; text-size:25%; text-align:center\"><b> 
            ERROR STATEMENT 11: Sorry! Our system is currently experiencing a problem! </b></h1> <br> 
            "); 
        } 
        

Edited by saversites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...