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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:44:58+00:00 2026-05-31T13:44:58+00:00

So I’m building a website where basically users can write stories and each story

  • 0

So I’m building a website where basically users can write stories and each story can have multiple continuations, but I’m trying to figure out how to query my database, so that I can return the first story and the continuations associated with that story, without getting repeated entries, which i would get if I’m just writing a join statement like so:

SELECT idStories, 
       Stories.Title, 
       Stories.Num_parts, 
       Stories.Story, 
       Stories.Date_poste,     
       idStory_continue, 
       Story_continue.Users_idUsers, 
       Story_continue.Title, 
       Story_continue.Story, 
       Story_continue.Date_posted, 
       Story_continue.Part_num 
  FROM Stories s
LEFT JOIN Story_continue sc ON sc.Stories_idStories = s.idStories   

so my question is what is an efficent way of returning this type of query without getting multiple versions of the original story. for instance when I query this I will get all of the original stories, and I will get the continuations, but it repeats the original story if there are multiple continuations to each story. and if you can’t make a query that provides information in this way, how would you go about solving this in php?

  • 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-31T13:44:59+00:00Added an answer on May 31, 2026 at 1:44 pm

    You can try a GROUP BY clause, but if you want all the story_continue data, you will need to do a GROUP_CONCAT which can get messy.
    I find it easier to split the query up like this. Usually it’s faster than a JOIN/GROUP BY anyways.

    $sql = "SELECT idStories, 
               Stories.Title, 
               Stories.Num_parts, 
               Stories.Story, 
               Stories.Date_posted
          FROM Stories";
    
    $stories = $db->fetchAll($sql);
    
    $ids = array();
    foreach($stories as $row){
        $ids[] = $row['idStories'];
    }
    $ids = implode(",",$ids);
    
    $sql = "SELECT idStory_continue, 
               Story_continue.Users_idUsers, 
               Story_continue.Title, 
               Story_continue.Story, 
               Story_continue.Date_posted, 
               Story_continue.Part_num,
               Stories_idStories
            FROM Story_continue IN ($ids)";
    
    $rows = $db->fetchAll($sql);
    
    $continues = array();
    foreach($rows as $row){
        // Continues can be referenced by the story id
        $continues[$row['Stories_idStories']][] = $row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.