cparekh Posted December 8, 2008 Share Posted December 8, 2008 Hi, this is probably an easy one but my mind is mush so I thought I'd ask here...hopefully someone can point me in the right direction.. I have a simple array and I want to join all the values into a single string. I'm writing a dynamic conditional statement for a sql query; The array is created based on certain criteria being met and then a single condition being created to insert into the sql query. What I have so far: $querybuild[] = "condition1"; $querybuild[] = "condition2"; $querybuild[] = "condition3"; etc.. //add the OR operator between array members for($i = 0, $size = sizeof($querybuild); $i < $size - 1; ++$i) { $querybuild[$i] = $querybuild[$i]. " OR "; } and now I'd like to join whatever the array holds into a single string to use in the sql query thus: $sql = "SELECT * FROM table WHERE ".$querybuild." ORDER BY id DESC"; where $querybuild would read "condition1 OR condition2 OR condition3". Hope that makes sense Thanks in advance for any help. C. Link to comment https://forums.phpfreaks.com/topic/136063-joining-together-values-of-an-array-into-a-single-string/ Share on other sites More sharing options...
Mchl Posted December 8, 2008 Share Posted December 8, 2008 implode Link to comment https://forums.phpfreaks.com/topic/136063-joining-together-values-of-an-array-into-a-single-string/#findComment-709462 Share on other sites More sharing options...
The Little Guy Posted December 8, 2008 Share Posted December 8, 2008 $str = implode(' OR ', $querybuild); $sql = "SELECT * FROM table WHERE ".$str." ORDER BY id DESC"; Link to comment https://forums.phpfreaks.com/topic/136063-joining-together-values-of-an-array-into-a-single-string/#findComment-709465 Share on other sites More sharing options...
cparekh Posted December 8, 2008 Author Share Posted December 8, 2008 Lol, boy do I feel daft!! thanx all! C. Link to comment https://forums.phpfreaks.com/topic/136063-joining-together-values-of-an-array-into-a-single-string/#findComment-709474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.