close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

MySQLi LIMIT 1 OFFSET 1 not working

Thread began 6/18/2018 4:50 am by Accumike | Last modified 6/19/2018 10:47 am by Accumike | 574 views | 1 replies

Accumike

MySQLi LIMIT 1 OFFSET 1 not working

I may be wrong, but it seems that you can't use the MySQL parameter OFFSET to find the penultimate record in a list.

For example, to find a User's previous login, the syntax would be something like:

SELECT id_log, datein_log FROM logger_log WHERE idusr_log= ? ORDER BY id_log DESC LIMIT 1 OFFSET 1

Unfortunately, this throws an error. I can't find the correct syntax on the WebAssist Community Forums, so I came up with a work around.

First find the Last Record, then use the ID of this record to find the Penultimate Record, whose ID will be less than the Last Record, as follows:

<?php
$rsLastLogin = new WA_MySQLi_RS("rsLastLogin",$yourdbconnection,1);
$rsLastLogin->setQuery("SELECT id_log, datein_log FROM logger_log WHERE idusr_log= ? ORDER BY id_log DESC");
$rsLastLogin->bindParam("i", "".$_SESSION['wa_user_id'] ."", "-1"); //colname
$rsLastLogin->execute();
?>

<?php $lastid = $rsLastLogin->getColumnVal("id_log"); ?>

<?php
$rsPenultimateLogin = new WA_MySQLi_RS("rsPenultimateLogin",$yourdbconnection,1);
$rsPenultimateLogin->setQuery("SELECT id_log, datein_log FROM logger_log WHERE idusr_log= ? AND id_log < ? ORDER BY id_log DESC");
$rsPenultimateLogin->bindParam("i", "".$_SESSION['wa_user_id'] ."", "-1"); //colname
$rsPenultimateLogin->bindParam("i", "".$lastid ."", "-1"); //colname2
$rsPenultimateLogin->execute();
?>

Then in your page, display in your preferred format:

<p>Last Login: <?php echo(date('d F Y H:i', strtotime($rsPenultimateLogin->getColumnVal("datein_log")))); ?></p>

A bit longwinded maybe, but I hope this helps anyone with the same issue.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...