How to get an array of values from a mysql column based on an array

Problem :

I'm new to PHP and as I'm getting into arrays its throwing me for a loop. No pun intended. Everything below is giving me what I need so far. $datum contains an array of submission ID's I need. What I'd like to do next is query a table to match all of my submission ID's in $datum to an Image ID column and put that result into an array containing all of the image ID's. Then I need to query the image table to get the file name for each of the Image ID's and put it into a SELECT box. Im just not sure how to work the loops with the arrays. I just can't make FOR EACH and WHILE do what I need. Ive put what Id like to do in plain english below the code. Thanks for any help.

$mask5 = $_GET["var1"];
$res = mysql_connect("", "", "");
//Get Category ID
$cat    = mysql_query("SELECT category FROM submissions WHERE submissions.submission_id='$mask5'");
$rows   = mysql_fetch_array($cat, MYSQL_ASSOC);
$array  = $rows['category'];
//Get Manufactuer ID
$man    = mysql_query("SELECT manufacturer_id FROM submissions WHERE submissions.submission_id='$mask5'");
$arows  = mysql_fetch_array($man, MYSQL_ASSOC);
$array1 = $arows['manufacturer_id'];
//Get All Submission ID's for this popup
$datum  = array();
$result = mysql_query("SELECT submission_id FROM submissions WHERE submissions.category='$array' AND submissions.manufacturer_id='$array1'");
while ($rowd = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $datum[] = $rowd;

////// WHAT ID LIKE TO DO.......

mysql_query("SELECT image_id FROM imagsub WHERE image_id = $datum[]...

$answers = new array from above result


mysql_query("SELECT filename FROM images WHERE image_id = $answers[]


Put into a select box.

Some of this I can struggle with and try to figure out but right now I can't seem to get an array of values from one column in a table based on another array. Any help with the rest is just gravy. Thanks in advance.

Solution :

It might be simpler if you create a query that joins all the data between your tables instead doing on PHP side. It's hard to understand your database and tables relationships, but definitely do it on SQL side, and don't query the database each time for each table you want to join.

Mysql Tutorials

Mysql Howto..

How to Limit Text Characters in PHP?

How to separate the rows depending of the column's value witin two tables in CodeIgniter?

How to check if mysql table is empty?

How to get stored variable value from mysql transaction

How to avoid creation of foreign keys on Django Models?

MySQL Query, how to group and count in one row?

How to count referalls mysql

How to reverse data of a column into another column in MySql?

How to rewrite this php slugify function to mysql?

MySQL stored procedure - How to Return Nothing

How to use BETWEEN mysql operator with the postCondition method?

How to normalize or design my MySQL database

How to append “OR” conditional operator to MySQL dynamic queries (PHP)?

how to store this date string in mysql db to allow sorting by date?

How does MySQL deal with connection per second, then decide to block connections?

how to combine multiple true/false rows in MYSQL

How to transpose MYSQL db in PHP

MySQL: How to fill new column of existing table with value based on select from another table [closed]

How do I count the number of visits to my site on a date with mysql?

How to add to an array in a database and get back each array and display it

How do you configure PHP to use mysql instead of sqlite

how to generate Data Base DB script in MySQL (MySQL Query Browser / Toad for MySQL)

How to insert data from a tornado web-socket to a mySQL database using Django

mySQL & Php, how to build a id checker

How can a 'WHERE column LIKE “%expression%” ' perform better than a MATCH(column) AGAINST(“expression”) in MySQL?

How to run append query from data macro MS Access?

Linux + MySQL: How to make outputs/responses visible?

how to group by a date range in MySQL and not skip dates with zero items

How to export / dump a MySql table into a text file including the field names (aka headers or column names)

Message system, showing conversation list