elpaisa Posted February 25, 2008 Share Posted February 25, 2008 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 https://forums.phpfreaks.com/topic/92923-insert-query-results-into-other-tables-field-delimiting-with-comma/ Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 <?php $comma_seperated = implode(",", $emails); $update = mysql_query("UPDATE banned SET email = ".$comma_seperated." WHERE id = '".$listid."' "); ?> Link to comment https://forums.phpfreaks.com/topic/92923-insert-query-results-into-other-tables-field-delimiting-with-comma/#findComment-476017 Share on other sites More sharing options...
elpaisa Posted February 25, 2008 Author Share Posted February 25, 2008 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 https://forums.phpfreaks.com/topic/92923-insert-query-results-into-other-tables-field-delimiting-with-comma/#findComment-476034 Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 look at the code above Link to comment https://forums.phpfreaks.com/topic/92923-insert-query-results-into-other-tables-field-delimiting-with-comma/#findComment-476058 Share on other sites More sharing options...
sasa Posted February 25, 2008 Share Posted February 25, 2008 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 https://forums.phpfreaks.com/topic/92923-insert-query-results-into-other-tables-field-delimiting-with-comma/#findComment-476138 Share on other sites More sharing options...
elpaisa Posted February 25, 2008 Author Share Posted February 25, 2008 Thanks sasa, that was exactly what i was looking for! Link to comment https://forums.phpfreaks.com/topic/92923-insert-query-results-into-other-tables-field-delimiting-with-comma/#findComment-476294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.