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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:19:10+00:00 2026-05-18T04:19:10+00:00

I am coding a movie archive script using codeigniter for myself with PHP. I

  • 0

I am coding a movie archive script using codeigniter for myself with PHP. I am getting movie’s information from IMDb and adding them to my database. I’m adding links for movies I selected using another table called links.

This is the query that I am using to get the movies from database:

    $movies = $this->db->query("SELECT *
  FROM movies
  ORDER BY ".$order['by']." ".$order['type']."
  LIMIT ".$limit.", " . $this->config->item('moviePerPage')
  );

and I am fetching it in view file like this:

foreach ($movies->result() as $row) {
  echo $row->name;
}

Now links must be shown for each movie with the matched IDs (movies could have more than one link). My links table has these columns: ‘id’, ‘movieid’, ‘name’, ‘link’

How can I get links for each movie with single MySQL query? Is is posible to get all links that related to current $row movie and bind them to a single variable as array? with this I can loop it with foreach() and show links for each movie.

btw: movies.movieid and links.movieid columns have the same data.

  • 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-18T04:19:10+00:00Added an answer on May 18, 2026 at 4:19 am

    I think you need mysql’s GROUP_CONCAT

    Do something like this:-

    SELECT 
        movies.*, 
        group_concat(links.link ', ') as links
    FROM movies 
    LEFT JOIN links 
    ON links.movieid = movies.movieid 
    GROUP BY movies.movieid
    

    You will get a comma separated list of links for every movie.
    Which you can extract like this:-

    foreach ($movies->result() as $row) {
      $linksArray = explode(",",$row->links);
    }
    

    Updates
    I think this is the only way you can get the results without having multiple result rows for a single movie with multiple links.

    Just be careful of the maximum length of characters you can get in the result – by default 1024 characters. Read this
    Mysql group_concat_max_length and Group concat max length to know how to override the limit.

    And like Dan Grossman has poined out, if you feel the links may contain comma, use a different or uncommon delimiter.

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

Sidebar

Related Questions

The coding is done using VS2008 There are two divs in my page namely
When coding web services, how do you structure your return values? How do you
In coding a traditional MVC application, what is the best practice for coding server-side
When coding, what in your experience is a better approach? Break the problem down
When coding, what is a good rule of thumb to keep in mind with
Our coding standards ask that we minimise the use of C# var (suggests limiting
During coding I frequently encounter this situation: I have several objects ( ConcreteType1 ,
Here's a coding problem for those that like this kind of thing. Let's see
I had been happily coding along on a decent sized solution (just over 13k
I've been coding alot of web-stuff all my life, rails lately. And i can

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.