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

I have decided to start coding using OOP and a PHP framework. I have
While coding python I'm using only 2 spaces to indent, sure PEP-8 really recommend
I have recently downloaded the FFmpeg-PHP extension (extracted from ffmpeg-php53-win32-vc9-all.zip) for PHP and I
In my application I m using following coding convention to open my default screen
I have been coding in python/django and c/c++ from last three years for various
I'm trying to get the following Google Apps script to work, taken from another
I am coding a simple movie timeline in Flash CS5 actionscript 3.0. I have
Please forgive the extreme-beginner style of coding. I'm working with PHP and JSON strings
I've apparently worked myself into a bad coding habit. Here is an example of
i've started on some basic java coding with gwt, and im getting a bit

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.