/    Sign up×
Community /Pin to ProfileBookmark

How To Fetch Not Last Row Of Table But Last Entry Of Certain User In The Table?

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.

[code]
$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>
“);
}
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 17.2019 — Could you just do this?
``<i>
</i>SELECT date_and_time FROM logins WHERE username = ? ORDER BY date_and_time DESC LIMIT 1<i>
</i>
``
×

Success!

Help @site-developer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...