Solved

PHP Function limit returning values

Posted on 2012-12-22
7
574 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 …

751 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