Solved

PHP Function limit returning values

Posted on 2012-12-22
7
548 Views
Last Modified: 2012-12-23
Hi all,

Here's a PHPFox script we are working on and need to alter a little bit:

 protected function getRows($sType = 'latest_activity')
        {
                switch ($sType)
                {
                        case 'recent_signups':
                                return Phpfox::getLib('phpfox.database')
                                          ->select('user_image, user_name, full_name, gender')
                                            ->from(Phpfox::getT('user'))
                                            ->limit($this->iRowsLimit)
                                                 ->where('view_id = 0')
                                            ->order('user_id DESC')
                                            ->execute('getRows');  
                                break;

                        case 'featured':
                                return Phpfox::getLib('phpfox.database')
                                          ->select('user_image, user_name, full_name, gender')
                                            ->from(Phpfox::getT('user'), 'a')
                                            ->join(Phpfox::getT('user_featured'), 'b', 'a.user_id = b.user_id')
                                            ->limit($rowsLimit)
                                                 ->where('view_id = 0')
                                            ->order('last_activity DESC')
                                            ->execute('getRows');  
                                break;

                        case 'latest_activity':
                        default:
                                return Phpfox::getLib('phpfox.database')
                                          ->select('user_image, user_name, full_name, gender')
                                            ->from(Phpfox::getT('user'))
                                            ->limit($this->iRowsLimit)
                                                 ->where('view_id = 0')
                                            ->order('last_activity DESC')
                                            ->execute('getRows');  
                                break;

                }
        }

Open in new window



All we need to do is add some code to this function so that it doesn't return the values where the user_image field is NULL. Could someone tell me how to do this?

Thank you,

D
0
Comment
Question by:TLN_CANADA
  • 4
  • 2
7 Comments
 
LVL 3

Assisted Solution

by:wadehults
wadehults earned 200 total points
ID: 38716632
I would add some logic to your cases. At present you are simply requesting database records. I'll use your default case to illustrate:

default:
         return Phpfox::getLib('phpfox.database')
             ->select('user_image, user_name, full_name, gender')
                     ->from(Phpfox::getT('user'))
                     ->limit($this->iRowsLimit)
                     ->where(('view_id = 0') && ('user_image' != null))                          
                     ->order('last_activity DESC')
                     ->execute('getRows');  
         break;

Let me know if this helps. Essentially, you are deselecting any database entries where there is a null value to the user_image and skipping to the next record.
0
 

Author Comment

by:TLN_CANADA
ID: 38716645
Thank you, for some reason this isn't working though.
0
 

Author Comment

by:TLN_CANADA
ID: 38716653
One of the PHPfox programmers suggested using "IS NOT NULL" instead in the script. Would you have any idea how to integrate this in the code?

Thank you!

D
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 300 total points
ID: 38716970
isn't working
doesn't give us much of a hint as to what might be wrong.  Any error messages that are generated?

In any case, here is what I would try with the WHERE clause.  It's just a guess because we cannot see the data.

 ->where('(view_id = 0 AND user_image IS NOT NULL)')

Note the grouping of parentheses carefully.  You want them inside the query WHERE clause, so that they are included inside the quoted literal string.  You also want them outside the quoted literal string so they define a wrapper around the quoted string.  Hence the paren-quote-paren notation.

HTH, ~Ray
0
 

Author Comment

by:TLN_CANADA
ID: 38717500
Thank you Ray! It's working now, as always your answers are right on the mark!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38717536
Thanks for the points and thanks for using EE.  Best holiday wishes, ~Ray
0
 

Author Comment

by:TLN_CANADA
ID: 38717537
Thanks Ray, wishing you a great Christmas also!
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now