Note that there are some explanatory texts on larger screens.

plurals
  1. POCombining MySQL queries
    primarykey
    data
    text
    <p>I have two seperate tables in my DB, here the relevant fields:</p> <p>table images:</p> <pre><code>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 ; </code></pre> <p>and table projects:</p> <pre><code>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 ; </code></pre> <p>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...</p> <p>So I would like to end up with</p> <pre><code>&lt;a href="index.php?page=projects&amp;id='.$projectid.'"&gt; &lt;img src="oldest_photo_of_project_x" /&gt; &lt;/a&gt; &lt;a href="index.php?page=projects&amp;id='.$projectid.'"&gt; &lt;img src="oldest_photo_of_project_y" /&gt; &lt;/a&gt; &lt;a href="index.php?page=projects&amp;id='.$projectid.'"&gt; &lt;img src="oldest_photo_of_project_z" /&gt; &lt;/a&gt; </code></pre> <p><strong>Update1:</strong></p> <p>To clarify I am trying to combine:</p> <pre><code>"SELECT * FROM projects WHERE user_id='$UserID' ORDER BY project_id DESC" </code></pre> <p>And maybe something like this:</p> <pre><code>$query = "SELECT images.project_id, projects.project_name ". "FROM images, projects ". "WHERE images.project_id = projects.project_id"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload