Jump to content

Issue with converting old SQL to new Capsule query


nodespace

Recommended Posts

Hello,

To preface this, I'm not a developer, but I've been trying to update some old code I have to work on my modern WHMCS installation. 

I'm trying to use this in a hook:

$result = Capsule::table('tbltickets')
                    ->join('tblticketreplies', 'tbltickets.id', '=', 'tblticketreplies.tid')
                    ->select('tbltickets.date', 'tblticketreplies.date', 'tbltickets.id')
                    ->where('tbltickets.id', '=', 'tblticketreplies.tid', 'and', 'tbltickets.admin', '=', '')
                    ->groupBy('tbltickets.id')
                    ->orderBy('tbltickets.date', 'DESC')
                    ->limit(10)
                    ->get();

If I echo out $result, I don't get anything (or I'm doing it wrong - big possibility!).

This code, which I use external to WHMCS, works flawlessly to grab the data I need:

$result = mysqli_query($connection, "SELECT tk.date, rp.date, tk.id FROM tbltickets as tk, tblticketreplies as rp WHERE tk.id=rp.tid AND tk.admin='' GROUP BY tk.id ORDER BY tk.date DESC LIMIT 0,10");

Any idea what I am doing wrong? I'd use the code that I'm using externally, but since I'm already inside WHMCS, it makes sense to just natively call the database.

Also, just for my sanity, I tried using the deprecated full_query function but same result - unable to get the data I need.

Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated