Jump to content

Insert query results into other table's field delimiting with comma


elpaisa

Recommended Posts

Hi all!

 

I need to select some emails from one table and insert them into another table's field deleimiting them with comma, for now this is what i have:

 

       foreach($_GET['id'] as $key => $value)
    { 
                  $select_query = mysql_query("SELECT email, name FROM members WHERE id = '$value' "); 
     $member = mysql_fetch_array($select_query);
                  $emails = $member['email'];
     $update = mysql_query("UPDATE banned SET email = ".$emails."   WHERE id = '".$listid."' "); 
     
                 echo '<span style=" font-family:Arial; color:red; font-weight:bold; font-size:12px;">added: '. $member['name'].' to users banned<br /></span>'; 

          	    }

It only inserts one email into banned field, what i need to do is insert all the emails retrieved from the first query and put them delimited by comma into banned field of the banned table

is not working i already tried this:

 

        foreach($_GET['id'] as $key => $value)
    { 
         $select_query = mysql_query("SELECT email, name FROM members WHERE id = '$value' "); 
     
	  while($member = mysql_fetch_array($select_query))
	  {
	   $emails = implode(",", $member['email']);
       $update = mysql_query("UPDATE banned SET email = '".$emails."'   WHERE id = '".$listid."' "); 
	 //echo '<span style=" font-family:Arial; color:red; font-weight:bold; font-size:12px;">added: '. $member['name'].' to users banned<br /></span>'; 
          }
	}

try

<?php
foreach($_GET['id'] as $key => $value) { 
$select_query = mysql_query("SELECT email, name FROM members WHERE id = '$value' "); 
while ($member = mysql_fetch_array($select_query)){
	$emails = $member['email'];
	$update = mysql_query("UPDATE banned SET email = CONCAT(email,',','".$emails."')   WHERE id = '".$listid."' "); 
	echo '<span style=" font-family:Arial; color:red; font-weight:bold; font-size:12px;">added: '. $member['name'].' to users banned<br /></span>'; 
}
}
?>

where yod define variable $listid used in query

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.