Better way to implode a query string? [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: Better way to implode a query string?

Post by incubi »

With your example If/when I put $allrows[] inside the while loop I get a serious buffer issues that ends in crashing my browser so I can't give the resulting error messages.

Isn't there a way to append a string to the last element in and array? Not appending a new element to the array but modifying the last element within the array? That would allow me to place the ending bracket and problem solved.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Better way to implode a query string?

Post by Eran »

There might be too many rows that you are running out of memory on the server (that shouldn't crash your browser though). You could stop every several iterations (say 10 or 20) insert the rows and reset the $allrows variable. Aside from that, I've given you a working solution - if you make the effort to understand what's going in there I'm sure you'll be able to complete your requirements
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: Better way to implode a query string?

Post by incubi »

Its only 400 rows of data in a csv file with 23 columns and the server is the company dual xeon 8G ram server so I'm betting it not that. I don't use IE so that's out :) I'll keep trying and see if I missed anything.

Thanks for the help.

incubi
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: Better way to implode a query string? [SOLVED]

Post by incubi »

pytrin

I found it, been a long day! I didn't put both the $row = array(); and the $allrows[] = "(" .implode(',',$row). ")"; in the loop. I called out the array $row before the loop and then when I moved it I had already moved the $allrows[] out of the loop. :crazy: I have a (Column count doesn't match value count at row 1) error but that's easy.

Thanks again for the help! Would you happen to have a working jetpack I can have too? :)

incubi
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Better way to implode a query string? [SOLVED]

Post by Eran »

cheers, glad it worked out. regarding the memory issue I mentioned - PHP has a memory allocation in its configuration file, and its much lower than the entire server memory (imagine each php process taking up all the memory available to the server). Sometimes it's atrociously low (~ few megabytes) which could easily run out of memory for large arrays.
Post Reply