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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:15:43+00:00 2026-05-26T09:15:43+00:00

I have this situation where i want to get data from 3 different databases,

  • 0

I have this situation where i want to get data from 3 different databases, say events, content and media and the look like this:

events

-------------------------
| e_id  | e_title       |
-------------------------
| 1 | event 1   |
| 2 | event 2   |
| 3 | event 3   |
-------------------------

content

-------------------------
| c_id  | c_title       |
-------------------------
| 1 | first event   |
| 2 | second event  |
| 3 | third event   |
-------------------------

media

-------------------------
| m_id  | m_title       |
-------------------------
| 1 | picture 1 |
| 1 | picture 2 |
| 1 | picture 3 |
-------------------------

Now i want to get the information from event 1, with the three pictures, so i have the following query


$result = mysql_query("
SELECT  events.e_id, events.e_title, content.c_id, content.c_title, media.m_id, media.m_content
FROM events 
INNER JOIN content 
ON events.e_id = content.c_id
INNER JOIN media 
ON events.e_id = media.m_id
WHERE events.e_id = '1'");

Now the point is, when i use

$show = mysql_fetch_assoc($result); 
echo($show['e_title']." - ".$show['m_title'])

I only get picture 1

when i use

while($show = mysql_fetch_assoc($result)){ 
echo($show['e_title']." - ".$show['m_title']);}

i get three times event 1

How can i combine this that my output will be something like:

event 1
 * picture 1
 * picture 2
 * picture 3

?

EDIT:

The solution below works fine, but now i have the following that doesn't work

while($show = mysql_fetch_assoc($result)){
    if($show['e_title'] !== $last_title){
        echo("<h3>".$show['e_title']."</h3>\n<ul>\n");
    }
    echo("\t<li>".$show['m_title']."</li>\n");
    if($show['e_title'] !== $last_title){
        echo("\t</ul>\n");
    }
    $last_title = $show['e_title'];
}

How can i achieve that my output will be like:

Event 1
 * picture 1
 * picture 2
 * picture 3

More info about event 1 (not shown in example)

?

  • 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-26T09:15:43+00:00Added an answer on May 26, 2026 at 9:15 am

    On every loop iteration, store the most recent used e_title in $last_title and only echo it out if it has changed ($show['e_title'] !== $last_title):

    $last_title = "";
    while($show = mysql_fetch_assoc($result)){ 
    
      // Display the title if it has changed
      if ($show['e_title'] !== $last_title) {
        echo $show['e_title'] . "\n";
      }
      echo "- " . $show['m_title'] . "\n";
    
      // Store the title to check in the next loop iteration
      $last_title = $show['e_title'];
    }
    

    Update If I understand what you’re trying to do with this, you need to test whether you have a <ul> open and if you do, close it before starting a new <h3> rather than closing it at the end of the loop.

    $ul_open = FALSE;
    while($show = mysql_fetch_assoc($result)){
        if($show['e_title'] !== $last_title){
            // Close an open <ul> if there is one...
            if ($ul_open) {
               echo "</ul>\n";
               $ul_open = FALSE;
    
               // Output additional info now...
               if (!empty($additional_info)) echo $additional_info;
            }
    
            // Now output the new header.
            echo("<h3>".$show['e_title']."</h3>\n<ul>\n");
    
            // And set the flag that there's an open <ul>
            $ul_open = TRUE;
    
            // And store additional info to use later...
            $additional_info = $show['somecolumn'];
        }
        // output the list item
        echo("\t<li>".$show['m_title']."</li>\n");
    
        $last_title = $show['e_title'];
    }
    // Now that the loop is finished, you must close the last remaining <ul>
    if ($ul_open) echo("\t</ul>\n");
    if (!empty($additional_info)) echo $additional_info;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where i want to return List<> from this function public
I have a situation where I want to fetch objects from my core data
I have a situation where I needed to get data from a form submit().
I have this situation where I want to display a list of Administration objects
I have a situation where my website needs to quickly retrieve data from my
I've got a situation which I want to fetch data from a database, and
I have this situation: { float foo[10]; for (int i = 0; i <
We have this situation: Window Keyboard ^ ^ | / ApplicationWindow so class Window
I have this situation: interface MessageListener { void onMessageReceipt(Message message); } class MessageReceiver {
I have this situation: There are a login page with a login form (form

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.