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 Quote 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."' "); ?> Quote 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>'; } } Quote 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 Quote 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 Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.