project3 Posted February 27, 2008 Share Posted February 27, 2008 ok, I have a multiple select box which I made an array Im trying to insert the values into the db. instead of inserting the values its inserting Array[1],Array[2] $this_new is what im inserting into the db at the bottom of the code below. $ix = 1; $array_count = count($this->MTime); $this_old = ""; while($ix <= $array_count){ if ($ix == 1){ $this_old .= "$this->MTime[$ix]"; }else{ $this_old .= ",$this->MTime[$ix]"; } $ix = $ix + 1; } $this_new = $this_old; Link to comment https://forums.phpfreaks.com/topic/93392-array-problem/ Share on other sites More sharing options...
Barand Posted February 27, 2008 Share Posted February 27, 2008 what does this give echo '<pre>'; print_r ($this->MTime); echo '</pre>'; Link to comment https://forums.phpfreaks.com/topic/93392-array-problem/#findComment-478431 Share on other sites More sharing options...
project3 Posted February 27, 2008 Author Share Posted February 27, 2008 what does this give echo '<pre>'; print_r ($this->MTime); echo '</pre>'; the sql is in an include file and I cant get text output to show up. If I just change the code to $this_new = $this->MTime[1]; and just select one it gets it ok. Link to comment https://forums.phpfreaks.com/topic/93392-array-problem/#findComment-478434 Share on other sites More sharing options...
project3 Posted February 27, 2008 Author Share Posted February 27, 2008 what does this give echo '<pre>'; print_r ($this->MTime); echo '</pre>'; I changed the code and took the array out of the " " and it worked. $ix = 0; $array_count = count($this->MTime); $array_count = $array_count - 1; $this_old = ""; while($ix <= $array_count){ if ($ix == 0){ $this_old .= $this->MTime[$ix]; }else{ $this_old .= ","; $this_old .= $this->MTime[$ix]; } $ix = $ix + 1; } $this_new = $this_old; Link to comment https://forums.phpfreaks.com/topic/93392-array-problem/#findComment-478450 Share on other sites More sharing options...
Barand Posted February 27, 2008 Share Posted February 27, 2008 In that case, instead of your while loop, try $this_new = join (',', $this->MTime); Link to comment https://forums.phpfreaks.com/topic/93392-array-problem/#findComment-478463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.