Ok, this might be confusing and so i hope I explain it properly.

I've 4 tables:

business photos video category

I wish to display "featured" companies around the webpage (or elsewhere) and I wish to show a Good or bad within the table row based on whether you will find photos or videos for your business.

Example: Joes Crab Shack doesn't have videos or photos but is featured. So, when his row is echoed out it'll show the company Title and Business Proprietor but there won't be any data within the photo or video cells thus within the video and photos column it'll refuse. Otherwise, when the opposite was true, it might say Yes.

Here's my pastebin

You are able to cheat just a little with something similar to this:

SELECT b.[other stuff],
(SELECT COUNT(1) FROM photos WHERE busid = b.id) AS photo_count,
(SELECT COUNT(1) FROM videos WHERE busid = b.id) AS video_count
FROM business AS b [etc]

photo_count &lifier video_count will return or more than - simple to obtain no/yes from in PHP. That will also steer clear of the duplicate results you'd get from getting a lot more than 1 photo/video per business.

Caveat!: transforming that towards the ORM you are using... I am unsure an ORM could be okay by using it. But when it isn't woofing within the "AS" aliasing in from() &lifier join(), you may can sneak the subqueries in select() with no problems.

I am likely to have a stab only at that.

Things I would do is, when producing the table for display of "featured" companies I'd create a call for your database, the main one generally made when producing the pics and vids groups and appearance the output. If there's something there then get it say yes, when the return in the database is null, it is a safe assumption there isn't any photos or videos and therefore you are able to print a No.

I am likely to assume here that the pics and vids tables contain a lot more than 1 record per business, a "someone to many" relationship.

Within this situation you are gonna need to re-think your approach or at best perform some formatting of the database results. Presently if Joes crab shack has a lot more than 1 videos and/or photos you are likely to have multiple recent results for Joes crab shack.

If you want photos/videos results you can format the outcomes when you are receiving them now to produce a multi dimensional array/object where $featured['videos'] or $featured['photos] would retain the outcomes of your join, in case your formatted array does not retain the 'videos' key then you've no video results.

If all that you should know is that if it's coming back a lot more than rows then create two new techniques inside your model to count videos and photos owed to some specific business. Now it's only a matter of echo'ing 'Yes' when the techniques return a lot more than rows or 'No' otherwise.

Edit: Model function need to look something similar to this

function frontPageList() {
    $this->db->select('b.busname, b.busowner, b.webaddress');
    $this->db->select('(SELECT COUNT(1) FROM photos WHERE busid = b.id) AS photo_count', FALSE);
    $this->db->select('(SELECT COUNT(1) FROM videos WHERE busid = b.id) AS video_count', FALSE);
    $this->db->from ('business AS b');
    $this->db->where('featured', '1');
    return $this->db->get();
}