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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:59:08+00:00 2026-06-04T13:59:08+00:00

I have two seperate tables in my DB, here the relevant fields: table images:

  • 0

I have two seperate tables in my DB, here the relevant fields:

table images:

CREATE TABLE `images` (
  `image_id` int(4) NOT NULL AUTO_INCREMENT,
  `project_id` int(4) NOT NULL,
  `user_id` int(4) NOT NULL,
  `image_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `image_description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `date_created` date NOT NULL,
  `link_to_file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `link_to_thumbnail` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `given_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `note` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`image_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=51 ;

and table projects:

CREATE TABLE `projects` (
  `project_id` int(4) NOT NULL AUTO_INCREMENT,
  `user_id` int(4) NOT NULL,
  `project_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `project_description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `date_created` date NOT NULL,
  `date_last_edited` date NOT NULL,
  `shared` int(1) NOT NULL,
  `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`project_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=25 ;

I would like to display in a variable $content, a gallery of the oldest image from each project as a link to that project page and I have no idea how the mysql query should be built. Can you please help me with this? I have tried several if and while statements but the results have been complete failures and i am at the end of my (very limited) knowledge. I’m about to jump out the window…

So I would like to end up with

<a href="index.php?page=projects&id='.$projectid.'">
  <img src="oldest_photo_of_project_x" />
</a>
<a href="index.php?page=projects&id='.$projectid.'">
  <img src="oldest_photo_of_project_y" />
</a>
<a href="index.php?page=projects&id='.$projectid.'">
  <img src="oldest_photo_of_project_z" />
</a>

Update1:

To clarify I am trying to combine:

"SELECT * FROM projects WHERE user_id='$UserID' ORDER BY project_id DESC"

And maybe something like this:

$query = "SELECT images.project_id, projects.project_name ". 
"FROM images, projects ".
"WHERE images.project_id = projects.project_id";
  • 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-04T13:59:10+00:00Added an answer on June 4, 2026 at 1:59 pm

    Haven’t tested for errors, but I’d do something like this:

    $result = mysql_query("SELECT DISTINCT 
        `projects`.`project_id` AS `project`, 
        `images`.`link_to_file` AS `filepath`
    FROM 
        `projects`,
        `images`
    WHERE 
        `projects`.`project_id` = `images`.`project_id`
    ORDER BY 
        `images`.`date_created` DESC");
    
    while ($resultLoop = mysql_fetch_array($result)) {
        $str .= '<a href="index.php?page=projects&id=' . $resultLoop["project"] . '">
            <img src="' . $resultLoop["filepath"] . '" />
        </a>';
    }
    
    
    echo $str;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view table which is a union of two separate tables (say
I have a query which searches two separate fields in the same table... looking
I have two tables, A and B and a simple table, X, that maintains
I have two tables (country & ducks) where the country table has every country
1) I have two tables: Photos table and EXIF table. EXIF table stores the
I have two separate sets of tables in the same database that model the
I have a list of addresses in two separate tables that are slightly off
I have two heroku accounts with two seperate applications. I am new at this
I have had this problem w/ two seperate WYSWYG editors in my rails application
I have a group of CFC's that I access from two seperate Applicaiton scopes.

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.