Hey All,
This is a real GAS and all, but I'm really stuck!
I'm able to generate the array I need (which will vary in size from time to time) but can't figure out how to utilize it to create the INSERT I need.

   $canvas_list_contacts =" select id from contacts where agency_name='FSBO'";
	$result = @mysql_query ($canvas_list_contacts)or die ("Query failed"); // Run the query.
 	// convert result set into array 
 	$array = array(); 
	while ($row = mysql_fetch_assoc($result)) {
    $array[] = $row[id];

 } // while 
// here's where I loose it...
// I'm thinking a foreach is involved
foreach ($array as $key => $value) { 
$populate_canvas_list = "INSERT INTO prospect_lists_prospects (id, prospect_list_id,related_id,related_type,date_modified,deleted)
  VALUES
  ('?', '4c1c90ac-e29d-b079-8c24-4550f759e92c','array[]','Contacts','now()','0'),
mysql_query( $populate_canvas_list);
}

Now, I don't THINK I need to populate ALL fields with this insert(date_modified or deleted could be null) but what about the 'id' field?

Anyway, any help would be greatly appreciated😃

    Since you can have multiple, comma-separated value lists in one INSERT command, I might do something like:

    // after your first query and population of $array....
    $values = array();
    foreach ($array as => $value)
    {
       $values[] = "('$value', '4c1c90ac-e29d-b079-8c24-4550f759e92c','array[]','Contacts','now()','0')";
    }
    $populate_canvas_list = ""INSERT INTO prospect_lists_prospects (id, prospect_list_id,related_id,related_type,date_modified,deleted)
      VALUES ".implode(', ', $values);
    $insert_result = mysql_query($populate_canvas_list) or die("Query failed: $populate_canvas_list - " . mysql_error());
    

      Thanks NogDog,

      I think I see where you are going with this, but right off the bat I get:

      Parse error: syntax error, unexpected T_DOUBLE_ARROW, 
      expecting '&' or T_STRING or T_VARIABLE or '$' in C:\..\canvas.php on line 13

      Here's the full script.

      <?php # Script test_canvas_list.php
      
      if (isset($_POST['submit'])) { // Handle the form.
      
      require_once ('mysql_connect.php'); // Connect to the db.
      mysql_select_db ('crm') OR DIE ("Could Not select database'crm':" . MYSQL_ERROR());
      
      $canvas_list_contacts =" select id from contacts where agency_name='FSBO'";
      $result = @mysql_query ($canvas_list_contacts)or die ("Query failed"); // Run the query.
      
      // after your first query and population of $array.... 
      $values = array(); 
      foreach ($array as => $value) 
      { 
      $values[] = "('', '4c1c90ac-e29d-b079-8c24-4550f759e92c','$value','Contacts','now()','0')"; 
      }
      $populate_canvas_list = ""INSERT INTO prospect_lists_prospects (id, prospect_list_id,related_id,related_type,date_modified,deleted) 
      VALUES ".implode(', ', $values); 
      $insert_result = mysql_query($populate_canvas_list) or die("Query failed: $populate_canvas_list - " . mysql_error()); 
      
      exit(); // Quit the script.
      
      // Print the error message if there is one.
      if (isset($message)) {
      	echo '<font color="red">', $message, '</font>';
      }
      
      	mysql_close(); // Close the database connection.
      }
      ?>
        <?php # Script test_canvas_list.php
        
        //create unique ID
        
        if (isset($_POST['submit'])) { // Handle the form.
        	require_once ('mysql_connect.php'); // Connect to the db.
        	mysql_select_db ('crm') OR DIE ("Could Not select database'crm':" . MYSQL_ERROR());
        
        $canvas_list_contacts =" select id from contacts where agency_name='FSBO'"; 
        $result = @mysql_query ($canvas_list_contacts)or die ("Query failed"); // Run the query. 
        
        // narrow query paramaters for single result and convert result set into array 
        while ($row = mysql_fetch_assoc($result)) { 
        $key = uniqid(rand(), true); 
        $targets[] = "('$key','4c1c90ac-e29d-b079-8c24-4550f759e92c','$row[id]','Contacts','null','null'"; 
        } 
        
        foreach ($targets as $key => $value) { 
        $populate_canvas_list = "INSERT INTO prospect_lists_prospects (id,prospect_list_id,related_id,related_type,date_modified,deleted)
        VALUES $value);";
        mysql_query($populate_canvas_list) or die('Query failed: $populate_canvas_list -  . mysql_error()');	
        
        }
        }
        
        exit(); // Quit the script.
        	mysql_close(); // Close the database connection.
        ?>
          Write a Reply...