Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:12:20+00:00 2026-05-23T01:12:20+00:00

i have a query that goes like this: $get_feed_amount = mysql_query( SELECT COUNT(*) as

  • 0

i have a query that goes like this:

            $get_feed_amount = mysql_query("

                SELECT COUNT(*) as num
                FROM `migo_feeds`
                WHERE
                (
                    (
                        feed_type='10' ||
                        feed_type='11' ||
                        feed_type='28' ||
                        feed_type='27' ||
                        feed_type='30' ||
                        feed_type='31'

                    )
                    AND
                    (
                        from_id IN (

                            SELECT DISTINCT from_id
                            FROM `migo_relations`
                            WHERE (
                                (to_id='".$_SESSION['user_id']."')

                                AND

                                (rel_processed='1' AND rel_accepted='1')
                            )                       

                        )

                        OR

                        to_id IN (

                            SELECT DISTINCT from_id
                            FROM `migo_relations`
                            WHERE (
                                (to_id='".$_SESSION['user_id']."')

                                AND

                                (rel_processed='1' AND rel_accepted='1')
                            )                               

                        )

                        OR

                        from_id=".$_SESSION['user_id']."

                        OR

                        to_id=".$_SESSION['user_id']."

                    )
                    AND
                    feed_deleted='0'
                );

            "); 

as you can see im allready selecting friends twice in this query

and also later i do queries like this:

            $migo_groups = mysql_query("

                SELECT 
                    group_id,
                    group_title,
                    group_desc,
                    group_cat_name,
                    group_area,
                    group_city,
                    group_quarter,
                    group_pic,
                    group_tmb,
                    group_members_amount
                FROM
                    `migo_groups`
                WHERE (

                    group_type=1

                    AND

                    group_id IN (

                        SELECT group_id
                        FROM `migo_group_membership`
                        WHERE (

                            membership_type IN (1,2,3)

                            AND

                            to_id IN (

                                SELECT DISTINCT from_id
                                FROM `migo_relations`
                                WHERE (
                                    (to_id='".$_SESSION['user_id']."')

                                    AND

                                    (rel_processed='1' AND rel_accepted='1')
                                )                                   
                            )
                        )
                    )
                )
                ORDER BY RAND() LIMIT 4;
            ");

selecting friends once again..
this seems a little bit of waste of resources. Especially if the tables are very large, things will probably take forever to load, or not even load at all.

My question is, can i just do a friend query in the beginning and use the result everywhere? Is that any good at all?

I was thinking perhaps save the resutls in an array or something, is that bad? What would be the best way to run things?

Regards,
Alexander

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:12:21+00:00Added an answer on May 23, 2026 at 1:12 am

    You can save the results of the first query in an array and then using only the array for your second need.

    Example:

    $result=array();
    $query=mysql_query("SELECT complex sql [...]");
    while($r = mysql_fetch_assoc($query)) {
        $result[] = $r;
        /*your first operation here*/
    }
    

    Now in your result you have all the results of the first query, and you can use that array to do your second operation without the need of other queries.

    foreach($result as $row) {
          // code
    }
    

    Also note you should use PDO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query that (stripped right down) goes something like this : SELECT
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query like this: SELECT TaFellesVaktjournal.*, TaBygg.ByggNavn FROM TaFellesVaktjournal LEFT JOIN TaBygg
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query that I'm executing from a .NET application to a SQL
I have a query that pulls up questions from one table and answers from
I have a query that I am generating the XML from in Oracle using
I have a query that is dynamically built after looking up a field list
I have a query that is currently using a correlated subquery to return the
I have a query that has 7 inner joins (because a lot of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.