Solved

PHP Function limit returning values

Posted on 2012-12-22
7
577 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 110

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 110

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 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