mongoose00318 Posted September 14, 2020 Share Posted September 14, 2020 I've been having issues with this since Friday and still haven't resolved it. If I call that function with a $order_id set to 7601 and the SQL clause says "LIMIT 1" I get a blank array that comes back. If I change it to LIMIT 2; I get the result I expected...but not two records...just the one? There are no blank records in the DB from what I see and if I run that same query in PHPMyAdmin it returns the results I expect? //build LED request buttons function build_led_request_btn($order_id, $pdo) { //info to gather //$order_id, $job_number, $enterprise, $request_id, $request_status //get request status $query = "SELECT * FROM leds_requests WHERE order_id = :order_id ORDER BY id DESC LIMIT 1"; $statement = $pdo->prepare($query); $statement->execute(['order_id' => $order_id]); $count_records = $statement->rowCount(); return $statement->fetch()['status_id']; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/311480-having-an-issue-with-limit-when-trying-to-select-most-recent-record/ Share on other sites More sharing options...
mac_gyver Posted September 14, 2020 Share Posted September 14, 2020 (edited) 32 minutes ago, mongoose00318 said: I get a blank array that comes back how do you know that, especially since you should be getting a status_id number as the returned value? perhaps there's some problem with the code that's using the result from calling that function? what is the (default) fetch mode you are using for the ->fetch() method call? have you set a default fetch mode yourself or are you using the default, default fetch mode? any chance you have more than one database and are selecting the wrong one? Edited September 14, 2020 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/311480-having-an-issue-with-limit-when-trying-to-select-most-recent-record/#findComment-1581369 Share on other sites More sharing options...
mongoose00318 Posted September 14, 2020 Author Share Posted September 14, 2020 @mac_gyver Man...okay the problem was elsewhere in my code. The query was working fine...I guess it I was looking at it too long Friday and couldn't see it. Sorry about that; it seems to be working now. But as to your question, I'm pretty sure I'm using the FETCH_ASSOC mode. Quote Link to comment https://forums.phpfreaks.com/topic/311480-having-an-issue-with-limit-when-trying-to-select-most-recent-record/#findComment-1581370 Share on other sites More sharing options...
mongoose00318 Posted September 14, 2020 Author Share Posted September 14, 2020 @mac_gyver Lol just noticed your sig...I don't know...I may have damaged my eyes Friday. Quote Link to comment https://forums.phpfreaks.com/topic/311480-having-an-issue-with-limit-when-trying-to-select-most-recent-record/#findComment-1581371 Share on other sites More sharing options...
Barand Posted September 14, 2020 Share Posted September 14, 2020 3 hours ago, mongoose00318 said: //info to gather //$order_id, $job_number, $enterprise, $request_id, $request_status According to that information in your comment, the records don't have a "status_id" Why the exit(); Quote Link to comment https://forums.phpfreaks.com/topic/311480-having-an-issue-with-limit-when-trying-to-select-most-recent-record/#findComment-1581383 Share on other sites More sharing options...
mongoose00318 Posted September 15, 2020 Author Share Posted September 15, 2020 @Barand There was additional code below the exit() that I thought was irrelevant to the post and I was trying to keep it short for everyone. Turns out the problem was in the code below the exit(); lol...it was there for debugging purposes. The comment is old; I originally was going pass all that to the function; but instead I just pass the order_id to it now. The rest of is provided elsewhere from other parts of the application. I should have the function buttoned up sometime today and I'll post it for review. It's a part of a big new feature I'm building into the application. I'm looking forward to getting it out to the end user. Quote Link to comment https://forums.phpfreaks.com/topic/311480-having-an-issue-with-limit-when-trying-to-select-most-recent-record/#findComment-1581413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.