Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Function limit returning values

Posted on 2012-12-22
7
Medium Priority
?
589 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 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
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.

 
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

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!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

783 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