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

Link to comment
Share on other sites

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>'; 
          }
	}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.