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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:56:21+00:00 2026-05-30T02:56:21+00:00

I’m using join to query data from two tables. For each a_id I need

  • 0

I’m using join to query data from two tables. For each a_id I need to get the associated image_id, filter those image_id results so only the first one remains, and finally output the results into an li. I think my query is good but I’m having a little trouble wrapping my head around how to get the image_id for each a_id and to output that to my li. This code returns some results but they are not what I’m looking for.

<?php
echo '<ul>';
$result = mysql_query ("SELECT * from artists left join images on artists.a_id = images.image_id where artists.display_works = '1' and artists.active = '1' order by artists.project_year desc, artists.fullname desc");

while ($row = mysql_fetch_array($result)){
    $data['a_id']['image_id']=$row->a_id;

    foreach($data as $id=>$images) {
            $totalimages=1;
            $addstyle = "";
            $art_id = $data['a_id'];
            $img_id = $data['image_id'];

            foreach($images as $val){

                    if($totalimages > 1){ $addstyle = 'style="display:none;"'; }
                    else {
                    $myimagename = "http://artists/$art_id/images/$img_id" .  "_large.jpg";
                    list($width, $height, $type, $attr) = getimagesize("$myimagename");
                    $myimagename = "http://artists/resize.php/$art_id/images/$img_id" . "_large.jpg?resize(157x2000)";

                    if($row["layout"] == "vert"){$pl = "_vertical";}else if($row["layout"] == "website"){$pl = "-s";}else if($row["layout"] == "video"){$pl = "_video";}else{$pl = "_horizontal";}
                    echo "<li class='thumbnail_container' $addstyle> <a class='thumbnail' href=\"../works$pl.php?a_id=" . $row["a_id"] . "\"><span><img src=\"$myimagename\" /></span>\n</a></li>\n";
                    }

                    $totalimages++;
        }
    }
}
echo '</ul>';
?>

Well, I’ve modified the code a bit and it’s working but for some reason I am getting an extra thumbnail after the first image with no image url or link url. I think it may have something to do with my method for checking for duplicate a_ids:

<?php
echo '<ul>';
$result = mysql_query ("SELECT * from artists left join images on artists.a_id = images.a_id where artists.display_works = '1' and artists.active = '1' order by artists.project_year desc, artists.fullname desc, images.position asc");

while ($row = mysql_fetch_array($result)){
    $check = $row['a_id'];
    if (in_array($check, $a_ids)) {end;}
    else { 
    $a_id=$row['a_id'];
    $a_ids[] = $a_id;
    $image_id=$row['image_id'];

    $myimagename = "http://artists/$a_id/images/$image_id" .  "_large.jpg";
    list($width, $height, $type, $attr) = getimagesize("$myimagename");
    $myimagename = "http://artists/resize.php/$a_id/images/$image_id" . "_large.jpg?resize(157x2000)";

    if($row["layout"] == "vert"){$pl = "_vertical";}else if($row["layout"] == "website"){$pl = "-s";}else   if($row["layout"] == "video"){$pl = "_video";}else{$pl = "_horizontal";}
        echo "<li class='thumbnail_container' $addstyle> <a class='thumbnail' href=\"../works$pl.php?a_id=" . $row["a_id"] . "\"><span><img src=\"$myimagename\" /></span>\n</a></li>\n";
    }
}
echo '</ul>';
?>
  • 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-30T02:56:23+00:00Added an answer on May 30, 2026 at 2:56 am

    Here is the solution that I ended up using. What was really making this difficult for me is that I wasn’t grasping two concepts.

    The first was JOIN. I didn’t understand how it was merging the two tables. After reading some more about it I now know that ON is more appropriate when joining columns of different names but what I really wanted was to JOIN both tables by their a_id columns. Even though I’ve left the ON and have made both column names the same I should look into using the keyword USING as it is specifically used for columns of the same name.

    The second concept I was having difficulty understanding was how to get all the info I wanted from the new joined table. I didn’t know that using mysql_fetch_array with a while loop would go through each row and get all the data from every column. Once I understood this though it was easy enough to go through each row and get the image_id and a_id.

    My final code:

    <?php
    echo '<ul>';
    $result = mysql_query ("SELECT * from artists left join images on artists.a_id = images.a_id where artists.display_works = '1' and artists.active = '1' order by artists.project_year desc, artists.fullname desc, images.position asc");
    
    while ($row = mysql_fetch_array($result)){
        $check = $row['a_id'];
        if (!in_array($check, $a_ids) && $check !='') {
        $a_id = $row['a_id'];
        $a_ids[] = $a_id;
        $image_id = $row['image_id'];
    
        $myimagename = "http://artists/$a_id/images/$image_id" .  "_large.jpg";
        list($width, $height, $type, $attr) = getimagesize("$myimagename");
        $myimagename = "http://artists/resize.php/$a_id/images/$image_id" . "_large.jpg?resize(157x2000)";
    
        if($row["layout"] == "vert"){$pl = "_vertical";}else if($row["layout"] == "website"){$pl = "-s";}else   if($row["layout"] == "video"){$pl = "_video";}else{$pl = "_horizontal";}
            echo "<li class='thumbnail_container' $addstyle> <a class='thumbnail' href=\"../works$pl.php?a_id=" . $row["a_id"] . "\"><span><img src=\"$myimagename\" /></span>\n</a></li>\n";
        }
    }
    echo '</ul>';
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.