close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Using LIMIT in MySQLi query

Thread began 7/07/2014 9:19 am by msummers194171 | Last modified 7/09/2014 12:35 pm by Jason Byrnes | 5948 views | 7 replies |

msummers194171

Using LIMIT in MySQLi query

OK - so I'm having a problem doing a query like this -

$rsQuotes->setQuery("SELECT quotes.quotes_quote FROM quotes WHERE quotes.quotes_display=1 LIMIT 1");

(I've also tried moving the LIMIT to just after the FROM statement)

I'm catching "Error in SQL Syntax" when I try that. Is this me or you or MySQLi?

Sign in to reply to this post

Jason ByrnesWebAssist

Make sure you have the latest version of the MySQLi extension installed, this is a bug that should be fixed.

The limit is passed through the recordset definition line.

so the line that instantiates the recordset object:

$rsQuotes = new WA_MySQLi_RS("rsQuotes",$<connectionName>,1);

that last argument "1" is the limit, rather than it being part of the SQL statement.

Sign in to reply to this post

msummers194171

YIKES - I knew that and forgot that I knew it!

I think I'm fully informed now, and you can relax for the rest of the day! :)

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

joe159765

So in a statement like "ORDER BY id DESC LIMIT 1, 1" where it goes 1 row back how would I call this with the MySQLi extension or am I just ill informed? Perhaps there's a better way? I'm trying to get the record right before the last record. Thanks.

Sign in to reply to this post

Jason ByrnesWebAssist

That limit statement doesn't look like it will do what you want, instead of using LIMIT in the recordset, use a loop to move the pointer to the last record, then move previous to move one back, then write the record to the page:


<?php 
while(!$RecordsetName->atEnd()) {
$RecordsetName->moveNext();
}
$RecordsetName->movePrevious();
echo($RecordsetName->getColumnVal("ColumnName"));
?>
Sign in to reply to this post

joe159765

Cool. Thanks Jason!

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

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...