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 7876737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:12:53+00:00 2026-06-03T03:12:53+00:00

The result stored in $g is 1 and 2. The following code I’ve written

  • 0

The result stored in $g is 1 and 2. The following code I’ve written below, my $array['music'] stores only the last element that is 2. But what I want is to execute my sql query 2 times under foreach and match the value of $g which is 1 and 2 with mu_id (mu_id is the column name from another table music) and store all the rows data of row 1 and 2 in to $array['music'].

It is storing only for the second row (2) not for 1 or it is overwriting it when it is executing for the second time inside loop. If there is any logic to make it work then please let me know.

    foreach($genre as $g)
    {
        echo $g;
        echo "<br>";
        $array['music'] = $m -> where('mu_id', $g ) -> get();
    }
  • 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-06-03T03:12:54+00:00Added an answer on June 3, 2026 at 3:12 am

    You’re redeclaring the entire array each time rather than adding to it, use this instead:

    foreach($genre as $g)
    {
        $array['music'][] = $m->where('mu_id', $g)->get();
    }
    

    Or even better, less queries:

    $array['music'] = $m->where_in('mu_id', $genre)->get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that returns a result with 250!!! columns. But I
I'm creating a temp table that's the result of a stored procedure's result set.
I have a MYSQL stored procedure SP1() that returns a result set. I want
I have the following representative code: __global__ void func() { register ushort4 result =
Suppose I'm using the following Oracle code in a stored procedure: CREATE GLOBAL TEMPORARY
I have the following code... $stored_date = date_format(date_create('now'), 'Y-m-d H:i:s'); echo 'Stored date: '
My user authorization process looks like that. During signin process function fires following code.
I am using zend_lucene for search functionality.I 've the following code, $doc->addField(Zend_Search_Lucene_Field::Text('categoryName', $result->name)); Here
I have the following PHP/MySQL code: function executeMultirowQuery($query) { $result = mysql_query($query); $table =
I'm using the following code to query a database from my jsp, but I'd

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.