newb Posted November 22, 2011 Share Posted November 22, 2011 How can i convert an array of results to a single comma separated string so that I can run it through an SQL query? Link to comment https://forums.phpfreaks.com/topic/251588-convert-array-to-comma-separated-string/ Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 implode Link to comment https://forums.phpfreaks.com/topic/251588-convert-array-to-comma-separated-string/#findComment-1290272 Share on other sites More sharing options...
newb Posted November 22, 2011 Author Share Posted November 22, 2011 K thanks. Link to comment https://forums.phpfreaks.com/topic/251588-convert-array-to-comma-separated-string/#findComment-1290286 Share on other sites More sharing options...
newb Posted November 22, 2011 Author Share Posted November 22, 2011 this worked better: foreach ($maintypes as $type) { $wheretype .= "'$type'"; } $wheretype = str_replace("''", "', '", $wheretype); $typesetting = @mysql_query("SELECT batch, quantity FROM batches WHERE type NOT IN ($wheretype) ORDER BY batch"); Link to comment https://forums.phpfreaks.com/topic/251588-convert-array-to-comma-separated-string/#findComment-1290289 Share on other sites More sharing options...
Fadion Posted November 22, 2011 Share Posted November 22, 2011 Hmm, you sure that works better? <?php $arr = array('some', 'comma', 'seperated', 'values'); $csv = "'" . implode("', '", $arr) . "'"; echo $csv; ?> Link to comment https://forums.phpfreaks.com/topic/251588-convert-array-to-comma-separated-string/#findComment-1290299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.