Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP Function limit returning values

Posted on 2012-12-22
7
Medium Priority
?
584 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 800 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1200 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 111

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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…

722 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