php-general Digest 1 May 2008 07:55:49 -0000 Issue 5434
php-general Digest 1 May 2008 07:55:49 - Issue 5434 Topics (messages 273738 through 273758): Re: Fun with SOAP. 273738 by: Larry Brown 273739 by: Nathan Nobbe Re: php 5 and mysql failure 273740 by: Shawn McKenzie 273741 by: Dan Joseph check if any element of an array is not empty 273742 by: afan pasalic 273743 by: Nathan Nobbe 273744 by: Richard Heyes 273745 by: afan pasalic 273746 by: Nathan Nobbe Re: Best practices for using MySQL index 273747 by: Chris 273749 by: Larry Garfield 273753 by: Shelley 273754 by: Shelley 273755 by: Chris Variable varialbe with array not working 273748 by: kronostar.aol.com problem imap_headerinfo 273750 by: Richard Kurth 273751 by: Chris 273752 by: Kalle Sommer Nielsen equivalent to perl shift function 273756 by: Richard Luckhurst 273757 by: Chris 273758 by: Richard Luckhurst Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- ---BeginMessage--- I'm not sure how it looks etc with with soapui but I noticed you mentioning you don't want to mess with nusoap. I've used nusoap for both client and server uses for years and I'm really impressed with how easily it works. Using $soapInstance-request and $soapInstance-response the xml is displayed where you can see how it was created based on the array you fed the instance before sending for your message. It makes troubleshooting much easier for me. That being said I don't send attachments. However just doing a quick google on nusoap attachments (without the quotes) has mention of people sending MIME attachments and one listing an issue with DIME encoded attachments yet another explaining that he solved the DIME encoded issue and referred to wrox book open source webservices page 315 which is an on-line book. Sorry no quick silver bullet, but I would highly recommend looking at nusoap if only as a test. Larry On Wed, 2008-04-30 at 08:21 -0400, Eric Butera wrote: On Wed, Apr 30, 2008 at 7:35 AM, Eric Butera [EMAIL PROTECTED] wrote: On Tue, Apr 29, 2008 at 5:07 PM, Nathan Nobbe [EMAIL PROTECTED] wrote: i know this has nothing to do w/ getting it to work w/ php, eric, but have you tried hitting the service w/ soap ui? http://www.soapui.org/ although its written in java, its an indispensable testing tool, imho, and i always give it a shot when im having soap troubles. i might try to see if you can get a successful response from the service w/ it. -nathan Hi Nathan! Thanks for the reply. I'm download it as we speak. Hopefully it'll give me some sort of answer as to what is going on. I really haven't found out enough about the SOAP standard enough to know what is expected behavior, etc. I know I can see all of the raw data there, just ext/soap doesn't seem to like the multi-part. Maybe soapUI will give me some sort of answer for this. After using soapUI I've determined that the SOAP response gives back an envelope and has one attachment. Does anyone know if the SOAP extension can handle attachments? I'd really rather not mess around with nusoap or the pear soap package. I don't see anywhere on the manual where it is possible to download attachments. Hopefully someone else has dealt with this before. -- Larry Brown [EMAIL PROTECTED] ---End Message--- ---BeginMessage--- On Wed, Apr 30, 2008 at 1:53 PM, Larry Brown [EMAIL PROTECTED] wrote: Sorry no quick silver bullet, but I would highly recommend looking at nusoap if only as a test. additionally, i could not find any occurrence of 'attachment' grepping through the c code in the soap extension or the rpc extension.. -nathan ---End Message--- ---BeginMessage--- Yehudi Alexis Garrett wrote: I'm using a php script which performs three xml queries to other three servers to retrieve a set of ids and after I do a query to mysql of the kind SELECT * FROM table WHERE id IN ('set of ids'); Although I'm sure the connection to the database is ok, I sometimes get an error of this kind: *Warning*: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in ... This does not happen every time i run the script, only sometimes. If I echo the query, copy and paste in phpmyadmin, or if I perform the same query in a script that does only the query without the rest it works! After troubleshooting this issue I noticed that it usually failed when I had a big set of ids (positive response from more than one server). This means that the script used a bigger amount of memory and probably more resources, but I did not get an out of memory error, I got the one described bfore. My
Re: [PHP] Best practices for using MySQL index
On Wed, Apr 30, 2008 at 7:03 PM, Aschwin Wesselius [EMAIL PROTECTED] wrote: Shelley wrote: Don't index just all integer fields. Keep track of the cardinality of a column. If you expect a field to have 100.000 records, but with only 500 distinct values it has no use to put an index on that column. A full record search is quicker. Hmmm... That's new. :) Well, to give you a good measure: keep the cardinality between 30 to 70-80 percent of your total records in a column. But sometimes your field is NULL or empty, so it really depends. You can't just put it into a standard configuration. And it also really depends on how many records a table contains etc. Besides that, benchmarking your development environment (you do have one do you?) can gives you a good idea on how your hardware and setup performs. I think I missed that part. For I am concerning query, index, and entity design most of the time. Aschwin Wesselius -- Regards, Shelley
Re: [PHP] Best practices for using MySQL index
On Thu, May 1, 2008 at 9:54 AM, Larry Garfield [EMAIL PROTECTED] wrote: On Wednesday 30 April 2008, Chris wrote: Index on most integer fields only. Text fields can be indexed, but is not important when you design your DB well. Don't index just all integer fields. Keep track of the cardinality of a column. If you expect a field to have 100.000 records, but with only 500 distinct values it has no use to put an index on that column. A full record search is quicker. Hmmm... That's new. :) To explain that further the idea is that if you have something like a 'status' field which can only hold 5 values, there's no point indexing it if there's a reasonably even spread. If you could only ever have a handful of fields with a status code of '1', then it's worth indexing if you have to find those particular records quickly. I don't think mysql supports partial indexes, but some databases do so you only index the fields that match a certain criteria. I'd suggest a more thorough approach to working out what to index rather than just trying to guess what's going on. Another piece of low-hanging-fruit is to index a field that you will be joining on frequently. The fact is, we seldom use join. Because we think it very slow to make it working on two tables with millions of records. Though we did not try it. :( Point above about spread still applies, but if you can join index to index, the join goes a lot faster. (A primary key in MySQL is always indexed.) How much is the *a lot*? Thanks. :) Having too many indexes rarely if ever costs on read (as far as I am aware), but it does cost on write to update the index. How much that matters is use-case specific. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Regards, Shelley
Re: [PHP] Best practices for using MySQL index
Point above about spread still applies, but if you can join index to index, the join goes a lot faster. (A primary key in MySQL is always indexed.) How much is the *a lot*? Thanks. :) If it's a unique (including primary) key then orders of magnitude for millions of rows. If it's a non-unique key, it depends on how many distinct values there are. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] equivalent to perl shift function
Hi All I am in the process of porting a perl script and I am trying to fin out if there is a php equivalent to the perl shift function? I have been looking at the php manual and google searching so far with no luck. Regards, Richard Luckhurst -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] equivalent to perl shift function
Richard Luckhurst wrote: Hi All I am in the process of porting a perl script and I am trying to fin out if there is a php equivalent to the perl shift function? I have been looking at the php manual and google searching so far with no luck. http://www.php.net/manual/en/function.array-shift.php -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] equivalent to perl shift function
Hi Chris, In perl ther is the concept of @_ which is the list of incoming parameter to a subroutine. It is possible to have something like my $sock = shift; As I understand this the first parameter of the @_ list would be shifted. I see for array_shift there must be an argument, the array name to shift, while in perl if the array name is omitted the @_ function list is used. Is ther a php equivalent to the @_ list or how might I use array_shift to achieve the same result as in perl? C Richard Luckhurst wrote: Hi All I am in the process of porting a perl script and I am trying to fin out if there is a php equivalent to the perl shift function? I have been looking at the php manual and google searching so far with no luck. C http://www.php.net/manual/en/function.array-shift.php Regards, Richard Luckhurst -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] equivalent to perl shift function
2008/5/1 Richard Luckhurst [EMAIL PROTECTED]: Hi Chris, In perl ther is the concept of @_ which is the list of incoming parameter to a subroutine. It is possible to have something like my $sock = shift; As I understand this the first parameter of the @_ list would be shifted. I see for array_shift there must be an argument, the array name to shift, while in perl if the array name is omitted the @_ function list is used. Is ther a php equivalent to the @_ list or how might I use array_shift to achieve the same result as in perl? I''ve no idea why you want to handle arguments in the same way as perl does - but func_get_args() returns the array of arguments to the function and you can shift that with array_shift() if you like. http://www.php.net/manual/en/function.func-get-args.php -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check if any element of an array is not empty
2008/4/30 Nathan Nobbe [EMAIL PROTECTED]: On Wed, Apr 30, 2008 at 2:58 PM, Richard Heyes [EMAIL PROTECTED] wrote: but I was thinking if there is the function does that. array_filter(). Note this: If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed. http://uk3.php.net/manual/en/function.array-filter.php i dont really see how that gets him the answer without at least checking the number of elements in the array after filtering it w/ array_filter; Because an empty array evaluates to false when cast to bool (which is implicit in a conditional). So this should work fine: if (array_filter($myArray)) { // only do this if there's stuff worth bothering with in myArray } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check if any element of an array is not empty
i dont really see how that gets him the answer without at least checking the number of elements in the array after filtering it w/ array_filter; which if he wanted to reuse in several places would make sense to write a simple function for anyway.. Yes, on both counts. -- Richard Heyes ++ | Access SSH with a Windows mapped drive | |http://www.phpguru.org/sftpdrive| ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Question regarding fopen
Does anyone have an idea? Is this a bug in PHP? Because when I add or remove one static letter in the filename, it does work. And if I don't the file is created, but the $imgstr (random 8 characters) is replaced by a totally different value (also random 8 characters).. I have no idea where this new value comes from. regards, Joep 2008/4/29 Joep Roebroek [EMAIL PROTECTED]: Hi, I'm having a strange problem with fopen For clearence, here is the phpinfo page: http://www.grondengoed.nl/phpinfo.php I will shortly explain the problem I'm having: $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder @mkdir($foldersystem); @chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } //$imagesmall, contains the image resource if(fwrite($handle, $imagesmall) === FALSE) { echo Cannot write to file (32); exit; } fclose($handle); Erverything works perfectly fine.But one thing, it doesn't give the file the name that it should get. A name for instance has to be: 54961tdtdtdtd-s0.jpg The number is the id of the database row, the 8 characters are random. -s stands for small and 0 is the picture index. When I echo the value, I get what I want. But when I save it, the random 8 character string had become a totally different 8 character string :S. I have googled and checked things over and over again, cost me hours and I still haven't found the reason. What is noticeable is that when I leave one character away from the name, the value IS what it schould be:S. I really hope you can help me, if you need further info yust ask. Thanks in advance. regards, Joep Roebroek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Question regarding fopen
?php $foldersystem = getcwd().'/test1'; $id = '54961'; $imgstr = 'tdtdtdtd'; //uniqid(); $i = 2; $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder mkdir($foldersystem); chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } This code works for me. How about you ? -- /James On Thu, May 1, 2008 at 11:04 AM, Joep Roebroek [EMAIL PROTECTED] wrote: Does anyone have an idea? Is this a bug in PHP? Because when I add or remove one static letter in the filename, it does work. And if I don't the file is created, but the $imgstr (random 8 characters) is replaced by a totally different value (also random 8 characters).. I have no idea where this new value comes from. regards, Joep 2008/4/29 Joep Roebroek [EMAIL PROTECTED]: Hi, I'm having a strange problem with fopen For clearence, here is the phpinfo page: http://www.grondengoed.nl/phpinfo.php I will shortly explain the problem I'm having: $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder @mkdir($foldersystem); @chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } //$imagesmall, contains the image resource if(fwrite($handle, $imagesmall) === FALSE) { echo Cannot write to file (32); exit; } fclose($handle); Erverything works perfectly fine.But one thing, it doesn't give the file the name that it should get. A name for instance has to be: 54961tdtdtdtd-s0.jpg The number is the id of the database row, the 8 characters are random. -s stands for small and 0 is the picture index. When I echo the value, I get what I want. But when I save it, the random 8 character string had become a totally different 8 character string :S. I have googled and checked things over and over again, cost me hours and I still haven't found the reason. What is noticeable is that when I leave one character away from the name, the value IS what it schould be:S. I really hope you can help me, if you need further info yust ask. Thanks in advance. regards, Joep Roebroek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] web based chat app
On Wednesday 30 April 2008 10:45:30 paragasu wrote: On Wed, Apr 30, 2008 at 4:28 PM, paragasu [EMAIL PROTECTED] wrote: You want light outta it?use the jabber2 server as a backend. It'll be done serving while you try to access the database. No need to do a square wheel, when a round one is invented is there any free jabber2 server i can use? i found the jabber2 main project website. but it is not suitable for what i wan't coz i want to integrate the chat to my website. so online member can chat to each other. i see a perl implementation but no php.. you build one. Thats the point of it wasn't it eh? A friend and I made a chat with jabber throught second life (the game) and a php webpage. -- --- Børge Holen http://www.arivene.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Question regarding fopen
Strangely enough.. It does.. But I have also tried adding a letter (which gives me the good result) and then renaming it... But then the value is wrong again :S I've never had a problem like this.. Very strange.. 2008/5/1 James Dempster [EMAIL PROTECTED]: ?php $foldersystem = getcwd().'/test1'; $id = '54961'; $imgstr = 'tdtdtdtd'; //uniqid(); $i = 2; $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder mkdir($foldersystem); chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } This code works for me. How about you ? -- /James On Thu, May 1, 2008 at 11:04 AM, Joep Roebroek [EMAIL PROTECTED] wrote: Does anyone have an idea? Is this a bug in PHP? Because when I add or remove one static letter in the filename, it does work. And if I don't the file is created, but the $imgstr (random 8 characters) is replaced by a totally different value (also random 8 characters).. I have no idea where this new value comes from. regards, Joep 2008/4/29 Joep Roebroek [EMAIL PROTECTED]: Hi, I'm having a strange problem with fopen For clearence, here is the phpinfo page: http://www.grondengoed.nl/phpinfo.php I will shortly explain the problem I'm having: $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder @mkdir($foldersystem); @chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } //$imagesmall, contains the image resource if(fwrite($handle, $imagesmall) === FALSE) { echo Cannot write to file (32); exit; } fclose($handle); Erverything works perfectly fine.But one thing, it doesn't give the file the name that it should get. A name for instance has to be: 54961tdtdtdtd-s0.jpg The number is the id of the database row, the 8 characters are random. -s stands for small and 0 is the picture index. When I echo the value, I get what I want. But when I save it, the random 8 character string had become a totally different 8 character string :S. I have googled and checked things over and over again, cost me hours and I still haven't found the reason. What is noticeable is that when I leave one character away from the name, the value IS what it schould be:S. I really hope you can help me, if you need further info yust ask. Thanks in advance. regards, Joep Roebroek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Question regarding fopen
Do you have a piece of example code that will reproduce the problem? -- /James On Thu, May 1, 2008 at 12:26 PM, Joep Roebroek [EMAIL PROTECTED] wrote: Strangely enough.. It does.. But I have also tried adding a letter (which gives me the good result) and then renaming it... But then the value is wrong again :S I've never had a problem like this.. Very strange.. 2008/5/1 James Dempster [EMAIL PROTECTED]: ?php $foldersystem = getcwd().'/test1'; $id = '54961'; $imgstr = 'tdtdtdtd'; //uniqid(); $i = 2; $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder mkdir($foldersystem); chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } This code works for me. How about you ? -- /James On Thu, May 1, 2008 at 11:04 AM, Joep Roebroek [EMAIL PROTECTED] wrote: Does anyone have an idea? Is this a bug in PHP? Because when I add or remove one static letter in the filename, it does work. And if I don't the file is created, but the $imgstr (random 8 characters) is replaced by a totally different value (also random 8 characters).. I have no idea where this new value comes from. regards, Joep 2008/4/29 Joep Roebroek [EMAIL PROTECTED]: Hi, I'm having a strange problem with fopen For clearence, here is the phpinfo page: http://www.grondengoed.nl/phpinfo.php I will shortly explain the problem I'm having: $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder @mkdir($foldersystem); @chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } //$imagesmall, contains the image resource if(fwrite($handle, $imagesmall) === FALSE) { echo Cannot write to file (32); exit; } fclose($handle); Erverything works perfectly fine.But one thing, it doesn't give the file the name that it should get. A name for instance has to be: 54961tdtdtdtd-s0.jpg The number is the id of the database row, the 8 characters are random. -s stands for small and 0 is the picture index. When I echo the value, I get what I want. But when I save it, the random 8 character string had become a totally different 8 character string :S. I have googled and checked things over and over again, cost me hours and I still haven't found the reason. What is noticeable is that when I leave one character away from the name, the value IS what it schould be:S. I really hope you can help me, if you need further info yust ask. Thanks in advance. regards, Joep Roebroek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Question regarding fopen
This problem is getting stranger by the minute. I will explain in a little more detail what the script is actually for.. It is an advert site and per advert, you can add 5 photo's.. Now you set the $i = 2; When I set the $i (which indictates the index of the photo, so $i = 5; is the last photo) myself, it works.. But normally I get the $i from the database, because there is stored how many photo's the already are in the advert.. When I use that value it doesn't work at all. When i set $i = 2.. It works :S,, but when the value it gets from the db also is 2 than it doesn't work (it is like it just doesn't want me to get it working :P)... Reproduction would be very difficult, because it is in this very specific situation... Maybe I am able to give you access to the FTP but that is a bit risky for me, not that I don't trust you, but the website is not mine.. regards, Joep 2008/5/1 James Dempster [EMAIL PROTECTED]: Do you have a piece of example code that will reproduce the problem? -- /James On Thu, May 1, 2008 at 12:26 PM, Joep Roebroek [EMAIL PROTECTED] wrote: Strangely enough.. It does.. But I have also tried adding a letter (which gives me the good result) and then renaming it... But then the value is wrong again :S I've never had a problem like this.. Very strange.. 2008/5/1 James Dempster [EMAIL PROTECTED]: ?php $foldersystem = getcwd().'/test1'; $id = '54961'; $imgstr = 'tdtdtdtd'; //uniqid(); $i = 2; $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder mkdir($foldersystem); chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } This code works for me. How about you ? -- /James On Thu, May 1, 2008 at 11:04 AM, Joep Roebroek [EMAIL PROTECTED] wrote: Does anyone have an idea? Is this a bug in PHP? Because when I add or remove one static letter in the filename, it does work. And if I don't the file is created, but the $imgstr (random 8 characters) is replaced by a totally different value (also random 8 characters).. I have no idea where this new value comes from. regards, Joep 2008/4/29 Joep Roebroek [EMAIL PROTECTED]: Hi, I'm having a strange problem with fopen For clearence, here is the phpinfo page: http://www.grondengoed.nl/phpinfo.php I will shortly explain the problem I'm having: $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder @mkdir($foldersystem); @chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } //$imagesmall, contains the image resource if(fwrite($handle, $imagesmall) === FALSE) { echo Cannot write to file (32); exit; } fclose($handle); Erverything works perfectly fine.But one thing, it doesn't give the file the name that it should get. A name for instance has to be: 54961tdtdtdtd-s0.jpg The number is the id of the database row, the 8 characters are random. -s stands for small and 0 is the picture index. When I echo the value, I get what I want. But when I save it, the random 8 character string had become a totally different 8 character string :S. I have googled and checked things over and over again, cost me hours and I still haven't found the reason. What is noticeable is that when I leave one character away from the name, the value IS what it schould be:S. I really hope you can help me, if you need further info yust ask. Thanks in advance. regards, Joep Roebroek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql query and maximum characters in sql statement
Hi, I have written a program which imports the tab delimited file and insert all the line from file to the mysql line by line. I am succeding in the above case. but problem with the above method is its taking to too much time while inserting into the database. The file's size will be more than 5000 lines. Then i tried to build a string of ; seperated queries. as follows for($i=1; $isizeof($array); $i++){ $insert_string .= insert into tablename (v1, v2. v6) values('$array[$i][1]', '$array[$i][2]'. '$array[$i][6]');; } if(!empty($insert_string)){ mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } Its throwing error saying check the manual for right syntax. After investigating in some sites i come to know that its problem of limitations in query size. I also tried with SET GLOBAL max_allowed_packet=3000; Then also its throwing the same error. Can anybody tell me how to fix this error and reduce the inserting time with a single statement instead of writing more insert statements -- Regards, Sanjeev http://www.sanchanworld.com http://webdirectory.sanchanworld.com - submit your site
Re: [PHP] Re: Question regarding fopen
Small correction $i = 4, means the last photo not 5.. Not so important but still.:P 2008/5/1 Joep Roebroek [EMAIL PROTECTED]: This problem is getting stranger by the minute. I will explain in a little more detail what the script is actually for.. It is an advert site and per advert, you can add 5 photo's.. Now you set the $i = 2; When I set the $i (which indictates the index of the photo, so $i = 5; is the last photo) myself, it works.. But normally I get the $i from the database, because there is stored how many photo's the already are in the advert.. When I use that value it doesn't work at all. When i set $i = 2.. It works :S,, but when the value it gets from the db also is 2 than it doesn't work (it is like it just doesn't want me to get it working :P)... Reproduction would be very difficult, because it is in this very specific situation... Maybe I am able to give you access to the FTP but that is a bit risky for me, not that I don't trust you, but the website is not mine.. regards, Joep 2008/5/1 James Dempster [EMAIL PROTECTED]: Do you have a piece of example code that will reproduce the problem? -- /James On Thu, May 1, 2008 at 12:26 PM, Joep Roebroek [EMAIL PROTECTED] wrote: Strangely enough.. It does.. But I have also tried adding a letter (which gives me the good result) and then renaming it... But then the value is wrong again :S I've never had a problem like this.. Very strange.. 2008/5/1 James Dempster [EMAIL PROTECTED]: ?php $foldersystem = getcwd().'/test1'; $id = '54961'; $imgstr = 'tdtdtdtd'; //uniqid(); $i = 2; $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder mkdir($foldersystem); chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } This code works for me. How about you ? -- /James On Thu, May 1, 2008 at 11:04 AM, Joep Roebroek [EMAIL PROTECTED] wrote: Does anyone have an idea? Is this a bug in PHP? Because when I add or remove one static letter in the filename, it does work. And if I don't the file is created, but the $imgstr (random 8 characters) is replaced by a totally different value (also random 8 characters).. I have no idea where this new value comes from. regards, Joep 2008/4/29 Joep Roebroek [EMAIL PROTECTED]: Hi, I'm having a strange problem with fopen For clearence, here is the phpinfo page: http://www.grondengoed.nl/phpinfo.php I will shortly explain the problem I'm having: $imagenamesmall = $foldersystem . '/' . $id . $imgstr . '-s' . $i . '.jpg'; echo $imagenamesmall; // For debugging purposses -- returns exactly what I want. //attempt to create folder @mkdir($foldersystem); @chmod($foldersystem, 0777); //save picture if(!($handle = fopen($imagenamesmall, 'w'))){ echo Cannot open file (31); exit; } //$imagesmall, contains the image resource if(fwrite($handle, $imagesmall) === FALSE) { echo Cannot write to file (32); exit; } fclose($handle); Erverything works perfectly fine.But one thing, it doesn't give the file the name that it should get. A name for instance has to be: 54961tdtdtdtd-s0.jpg The number is the id of the database row, the 8 characters are random. -s stands for small and 0 is the picture index. When I echo the value, I get what I want. But when I save it, the random 8 character string had become a totally different 8 character string :S. I have googled and checked things over and over again, cost me hours and I still haven't found the reason. What is noticeable is that when I leave one character away from the name, the value IS what it schould be:S. I really hope you can help me, if you need further info yust ask. Thanks in advance. regards, Joep Roebroek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
Re: [PHP] Fun with SOAP.
On Wed, Apr 30, 2008 at 3:53 PM, Larry Brown [EMAIL PROTECTED] wrote: I'm not sure how it looks etc with with soapui but I noticed you mentioning you don't want to mess with nusoap. I've used nusoap for both client and server uses for years and I'm really impressed with how easily it works. Using $soapInstance-request and $soapInstance-response the xml is displayed where you can see how it was created based on the array you fed the instance before sending for your message. It makes troubleshooting much easier for me. That being said I don't send attachments. However just doing a quick google on nusoap attachments (without the quotes) has mention of people sending MIME attachments and one listing an issue with DIME encoded attachments yet another explaining that he solved the DIME encoded issue and referred to wrox book open source webservices page 315 which is an on-line book. Sorry no quick silver bullet, but I would highly recommend looking at nusoap if only as a test. Hi Larry, I am receiving a multipart mime attachment from Amazon. The idea is we request a report and get a response. This response differs from any other response I have seen in that it is multipart. I searched all over the place for a way to get it to work correctly. The soapUI program is the only one so far that has been able to show me that I get a proper return value that can be parsed. soapUI shows me the envelope XML and then has a button on the bottom that says there is an attachment that I can save to a file. So from this I know that it is possible to handle this type of request correctly. I just haven't been able to find any real examples on how to use it. I wanted to keep everything using ext/soap since it is c code and very fast. Plus there are other parts of this program already utilizing it. So far I have my backup plan working using curl, a regex, and simplexml. ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] extending Xpath
Hi, I was wondering if it was possible to extend the DOMXpath object in a similar fashion to the DomDocument. I was hoping to write a wrapper to provide an interface similar to prepared statements in the db libraries for the xpath processor. $xpath = new myxpath(); $stmt = $xpath-prepare(/foo/[EMAIL PROTECTED] = '?' ]); $stmt-bindParam( '?', $potentiallynastystring ); $x = $stmt-execute(); I have tried : final class timber_utils_domxpath extends DomXpath { public function __construct( DOMDocument $dom ) { echo in here; parent::_construct( $dom ); } } but I get the following error Fatal error: Call to undefined method DOMXPath::_construct() Many thanks Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] web based chat app
you build one. Thats the point of it wasn't it eh? A friend and I made a chat with jabber throught second life (the game) and a php webpage. interesting. i really wan't to try out your chat implementation. may i? i don't know how to integrate php with jabber since i don't have much understanding on how jabber works.. :).. may give me some idea..
Re: [PHP] Xampp question, pretty much 0T
/* Top posting from my cell... 1. Format hard drive 2. Install redhat fc8 or Ubuntu 8.04 3. Load the new MySQL installation with your backup file If you really have to stay with windoze, remove and re-install apache. Look at the system log files as they SHOULD tell you what was causing the crash. */ Hey Wolf, Thanks for replying. Would love to install Linux, problem is... dont know the first thing about it if things go wrong, I always wanted to learn what its all about but when I started to read up on it quickly got confused with all the different flavors out there... which one is right for me/ a total beginner? for every little thing I would probably have to join a linux list and post.. what about drivers for the bits and pieces of the laptop? what about software? most of the places I go to download software (freeware or shareware) is only for Win.. Would love to switch away from Win... but i think the OS guys will have to make it seem less of a mountain to climb to do so :( Cheers! R Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Xampp question, pretty much 0T
On May 1, 2008, at 8:56 AM, Ryan S wrote: /* Top posting from my cell... 1. Format hard drive 2. Install redhat fc8 or Ubuntu 8.04 3. Load the new MySQL installation with your backup file If you really have to stay with windoze, remove and re-install apache. Look at the system log files as they SHOULD tell you what was causing the crash. */ Hey Wolf, Thanks for replying. Would love to install Linux, problem is... dont know the first thing about it if things go wrong, I always wanted to learn what its all about but when I started to read up on it quickly got confused with all the different flavors out there... which one is right for me/ a total beginner? for every little thing I would probably have to join a linux list and post.. what about drivers for the bits and pieces of the laptop? what about software? most of the places I go to download software (freeware or shareware) is only for Win.. Would love to switch away from Win... but i think the OS guys will have to make it seem less of a mountain to climb to do so :( One option, I don't know what your budget is, but Apple's Macintosh OS X is basically a flavor of Unix (FreeBSD if I remember right) with a nice user interface on it. You have the ability to dive into the commandline when you need to/ want to, but have the comfortable point/click user interface when you don't want to worry about it. Just something else to think about... Oh... And there's no virii for the Mac :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Categories like wordpress
Hey! Heres what i have to do, upload pics and each pic can be a part of x number of categores for example: A picture of a rose can be for birthday, as well as anniversary, or miss you, or love etc exactly the same as how in wordpress an article can be in multiple categories like tech, current news, gadgets etc Was wondering how to do this, and please tell me if I am on the wrong path but: in the mysql db next to img name have a field called cate (or whatever for categories) and have a comma seperated list for each of the categories that the pic falls into and then do a mySql LIKE '%$param%' search if the user wants 'birthday'? Is this how its done or am I barking up the wrong tree? TIA /R Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
On Thu, May 1, 2008 at 9:23 AM, Ryan S [EMAIL PROTECTED] wrote: Hey! Heres what i have to do, upload pics and each pic can be a part of x number of categores for example: A picture of a rose can be for birthday, as well as anniversary, or miss you, or love etc exactly the same as how in wordpress an article can be in multiple categories like tech, current news, gadgets etc Was wondering how to do this, and please tell me if I am on the wrong path but: in the mysql db next to img name have a field called cate (or whatever for categories) and have a comma seperated list for each of the categories that the pic falls into and then do a mySql LIKE '%$param%' search if the user wants 'birthday'? Is this how its done or am I barking up the wrong tree? TIA /R ** Well you could go with a comma separated list of keywords, or you could build a keywords table, and then a table for associating each picture with a given keyword. So you have your images table with your image information, then you have your keywords table with your keyword information, then an associations table with the image id and keyword id link. Either way should work ok. -- -Dan Joseph Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life.
Re: [PHP] Xampp question, pretty much 0T
/* Top posting from my cell... 1. Format hard drive 2. Install redhat fc8 or Ubuntu 8.04 3. Load the new MySQL installation with your backup file If you really have to stay with windoze, remove and re-install apache. Look at the system log files as they SHOULD tell you what was causing the crash. */ Hey Wolf, Thanks for replying. Would love to install Linux, problem is... dont know the first thing about it if things go wrong, I always wanted to learn what its all about but when I started to read up on it quickly got confused with all the different flavors out there... which one is right for me/ a total beginner? for every little thing I would probably have to join a linux list and post.. what about drivers for the bits and pieces of the laptop? what about software? most of the places I go to download software (freeware or shareware) is only for Win.. Would love to switch away from Win... but i think the OS guys will have to make it seem less of a mountain to climb to do so :( reply One option, I don't know what your budget is, but Apple's Macintosh OS X is basically a flavor of Unix (FreeBSD if I remember right) with a nice user interface on it. You have the ability to dive into the commandline when you need to/ want to, but have the comfortable point/click user interface when you don't want to worry about it. Just something else to think about... Oh... And there's no virii for the Mac :) /reply Cant afford a new comp or a new OS and as for your last statement: http://www.sophos.com.au/pressoffice/news/articles/2006/02/macosxleap.html _almost_ no virii for the Mac :) Cheers! R Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql query and maximum characters in sql statement
Sanjeev N [EMAIL PROTECTED] wrote: Hi, I have written a program which imports the tab delimited file and insert all the line from file to the mysql line by line. I am succeding in the above case. but problem with the above method is its taking to too much time while inserting into the database. The file's size will be more than 5000 lines. Then i tried to build a string of ; seperated queries. as follows for($i=1; $isizeof($array); $i++){ $insert_string .= insert into tablename (v1, v2. v6) values('$array[$i][1]', '$array[$i][2]'. '$array[$i][6]');; } if(!empty($insert_string)){ mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } Its throwing error saying check the manual for right syntax. After investigating in some sites i come to know that its problem of limitations in query size. I also tried with SET GLOBAL max_allowed_packet=3000; Then also its throwing the same error. Can anybody tell me how to fix this error and reduce the inserting time with a single statement instead of writing more insert statements Sure, check with a MySQL list via http://www.mysql.com Otherwise, split it up into multiple inserts. I currently have a script which reads a 550,000 CSV file and uses ?php // read file // for each line, do the following while ($in != EOF) { $line=explode (',',$in); $out=insert into table values('','$line[0]', .); fwrite ($outf, $out); } then I have another file that ?php //read the file line by line //connect to db $sql = $inLine; mysql_query($sql) or die(); ? which all in all takes about 10 seconds to run the conversion and then the inserts. HTH, Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Xampp question, pretty much 0T
On May 1, 2008, at 9:30 AM, Ryan S wrote: /* Top posting from my cell... 1. Format hard drive 2. Install redhat fc8 or Ubuntu 8.04 3. Load the new MySQL installation with your backup file If you really have to stay with windoze, remove and re-install apache. Look at the system log files as they SHOULD tell you what was causing the crash. */ Hey Wolf, Thanks for replying. Would love to install Linux, problem is... dont know the first thing about it if things go wrong, I always wanted to learn what its all about but when I started to read up on it quickly got confused with all the different flavors out there... which one is right for me/ a total beginner? for every little thing I would probably have to join a linux list and post.. what about drivers for the bits and pieces of the laptop? what about software? most of the places I go to download software (freeware or shareware) is only for Win.. Would love to switch away from Win... but i think the OS guys will have to make it seem less of a mountain to climb to do so :( reply One option, I don't know what your budget is, but Apple's Macintosh OS X is basically a flavor of Unix (FreeBSD if I remember right) with a nice user interface on it. You have the ability to dive into the commandline when you need to/ want to, but have the comfortable point/click user interface when you don't want to worry about it. Just something else to think about... Oh... And there's no virii for the Mac :) /reply Cant afford a new comp or a new OS and as for your last statement: http://www.sophos.com.au/pressoffice/news/articles/2006/02/macosxleap.html _almost_ no virii for the Mac :) None that have effected my computers here at work, or at home. No anti- virus, no firewall's ;) Oh and I'll take 1 over 97,467 anyday :) http://www.macdailynews.com/index.php/weblog/comments/5393/ -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
Is this how its done or am I barking up the wrong tree? You have multiple options: 1. Fully normalised, where you have three tables - one for your articles, one for your categories and a link table. 2. A SET MySQL datatype which will allow upto 32 predefined categories. 3. A simple CHAR type with the category names, (or if you use numeric IDs, you could have many more categories). The former is, IIRC, faster, but more work to implement. Whereas the latter two are very fast to implement but somewhat slower to query. For the last two cases the MySQL function FIND_IN_SET() will be very useful. -- Richard Heyes ++ | Access SSH with a Windows mapped drive | |http://www.phpguru.org/sftpdrive| ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
On May 1, 2008, at 743AM, Richard Heyes wrote: Is this how its done or am I barking up the wrong tree? You have multiple options: 1. Fully normalised, where you have three tables - one for your articles, one for your categories and a link table. This is the route that I would suggest, it's the most flexible and fastest to query. Just to expound a little... images table: - image_id - image_filename category table - category_id - category_name image_category_mapping table: - image_id - category_id Then when you want to get all of the images for a category: SELECT image_id, image_filename FROM images JOIN image_category_mapping ON images.image_id = image_category_mapping.image_id WHERE category_id = 10; Getting all the categories an image is in: SELECT category_id FROM image_category_mapping WHERE image_id = 42; It seems like more work than the route you described, but it's way more flexible, and as Richard pointed out, it's fully normalized. Brady -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] extending Xpath
Andrew Mason wrote: Hi, I was wondering if it was possible to extend the DOMXpath object in a similar fashion to the DomDocument. I was hoping to write a wrapper to provide an interface similar to prepared statements in the db libraries for the xpath processor. $xpath = new myxpath(); $stmt = $xpath-prepare(/foo/[EMAIL PROTECTED] = '?' ]); $stmt-bindParam( '?', $potentiallynastystring ); $x = $stmt-execute(); I have tried : final class timber_utils_domxpath extends DomXpath { public function __construct( DOMDocument $dom ) { echo in here; parent::_construct( $dom ); } } but I get the following error Fatal error: Call to undefined method DOMXPath::_construct() Your missing an underscore. It needs two not one. Many thanks Andrew -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
it's the most flexible and fastest to query. Mmm, that's debateable. Not knowing the ins and outs of MySQL I'd hazard a guess that reading an extra 255 bytes from the table file might be faster in some circumstances than opening two extra table files. And I don't see why it's more flexible...? The latter two solutions I suggested are certainly easier to work with and (with todays hardware), speed isn't always a factor. -- Richard Heyes ++ | Access SSH with a Windows mapped drive | |http://www.phpguru.org/sftpdrive| ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Xampp question, pretty much 0T
Cant afford a new comp or a new OS and as for your last statement: http://www.sophos.com.au/pressoffice/news/articles/2006/02/macosxleap.html _almost_ no virii for the Mac :) /* None that have effected my computers here at work, or at home. No anti- virus, no firewall's ;) Oh and I'll take 1 over 97,467 anyday :) http://www.macdailynews.com/index.php/weblog/comments/5393/ */ Haha fair enough... but that will still leave you owning a Mac... will rather have the viruses than the shame! Plus you know nearly any software you download (shareware/freeware or even pirated) will support windows.. can you say the same for the Mac? Anyway, lets not take this down the my daddy can beat up your daddy lane and make this into a Apple against M$ thread. Cheers! R Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Xampp question, pretty much 0T
On May 1, 2008, at 11:43 AM, Ryan S wrote: Cant afford a new comp or a new OS and as for your last statement: http://www.sophos.com.au/pressoffice/news/articles/2006/02/macosxleap.html _almost_ no virii for the Mac :) /* None that have effected my computers here at work, or at home. No anti- virus, no firewall's ;) Oh and I'll take 1 over 97,467 anyday :) http://www.macdailynews.com/index.php/weblog/comments/5393/ */ Haha fair enough... but that will still leave you owning a Mac... will rather have the viruses than the shame! Plus you know nearly any software you download (shareware/freeware or even pirated) will support windows.. can you say the same for the Mac? Anyway, lets not take this down the my daddy can beat up your daddy lane and make this into a Apple against M$ thread. Don't intend to, so I'll stop after this next point :) Over 25,000+ commercial products for the mac Probably at least as many shareware/freeware aps and with the new Mac's if you REALLY need to you can subject it to running windows so it can basically run every single piece of software out there :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
Hey! Thanks for replying guys! clip 1. Fully normalised, where you have three tables - one for your articles, one for your categories and a link table. This is the route that I would suggest, it's the most flexible and fastest to query. /clip Anyone happen to have a little PHP code as an example here ( a little more than Brady gave me)? or links to where i can read up on this mySql and php side as I have never done anything like this before. TIA, R Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql query and maximum characters in sql statement
Sanjeev N wrote: Hi, I have written a program which imports the tab delimited file and insert all the line from file to the mysql line by line. I am succeding in the above case. but problem with the above method is its taking to too much time while inserting into the database. The file's size will be more than 5000 lines. Then i tried to build a string of ; seperated queries. as follows for($i=1; $isizeof($array); $i++){ $insert_string .= insert into tablename (v1, v2. v6) values('$array[$i][1]', '$array[$i][2]'. '$array[$i][6]');; } if(!empty($insert_string)){ mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } Its throwing error saying check the manual for right syntax. After investigating in some sites i come to know that its problem of limitations in query size. I also tried with SET GLOBAL max_allowed_packet=3000; Then also its throwing the same error. Can anybody tell me how to fix this error and reduce the inserting time with a single statement instead of writing more insert statements You are probably looking for something like this. ?php if ( count($array) ) { $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; $data = array(); foreach ( $array AS $row ){ $row_clean = array_map('mysql_real_escape_string', $row); $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); } $insert_string = join(', ', $data); mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } else { echo Nothing to insert; } ? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
On May 1, 2008, at 843AM, Richard Heyes wrote: it's the most flexible and fastest to query. Mmm, that's debateable. Not knowing the ins and outs of MySQL I'd hazard a guess that reading an extra 255 bytes from the table file might be faster in some circumstances than opening two extra table files. And I don't see why it's more flexible...? Good point, I should have said can be more flexible and faster to query. I've found that every time I try to do something like this without having a mapping table that I eventually end up wanting to move to the mapping table setup. Of course that might just be because I'm so used to doing it that way. Certainly that doesn't mean that other solutions are wrong or bad in any way. I need to learn to not speak in absolutes. :) The latter two solutions I suggested are certainly easier to work with and (with todays hardware), speed isn't always a factor. Yes, another great point. Brady -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql query and maximum characters in sql statement
Jim Lucas wrote: Sanjeev N wrote: Hi, I have written a program which imports the tab delimited file and insert all the line from file to the mysql line by line. I am succeding in the above case. but problem with the above method is its taking to too much time while inserting into the database. The file's size will be more than 5000 lines. Then i tried to build a string of ; seperated queries. as follows for($i=1; $isizeof($array); $i++){ $insert_string .= insert into tablename (v1, v2. v6) values('$array[$i][1]', '$array[$i][2]'. '$array[$i][6]');; } if(!empty($insert_string)){ mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } Its throwing error saying check the manual for right syntax. After investigating in some sites i come to know that its problem of limitations in query size. I also tried with SET GLOBAL max_allowed_packet=3000; Then also its throwing the same error. Can anybody tell me how to fix this error and reduce the inserting time with a single statement instead of writing more insert statements You are probably looking for something like this. ?php if ( count($array) ) { $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; $data = array(); foreach ( $array AS $row ){ $row_clean = array_map('mysql_real_escape_string', $row); $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); } $insert_string = join(', ', $data); mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } else { echo Nothing to insert; } ? That would work, but will probably result in a query string that is too long. I'll redo the above to fix that. ?php # How often do you want to insert?? $break_at = 100; # Initialize the counter $cnt = 0; # Initial insert string $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; # if there is data, then process, otherwise skip it. if ( count($array) ) { $data = array(); # Loop through data foreach ( $array AS $row ) { $cnt++; # Clean the result data $row_clean = array_map('mysql_real_escape_string', $row); # Build data string and push it onto the data array. $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); # Break and insert if we are at the break point if ( $cnt === $break_at ) { # Reset Counter $cnt = 0; # Run insert mysql_query($insert_string . join(', ', $data), $conn) or die(query failed : .mysql_error()); # Reset data array $data = array(); } //if } //foreach # This should take care of any extra that didn't get processed in the foreach if ( count($data) ) { # Insert remaining data mysql_query($insert_string . join(', ', $data), $conn) or die(query failed : .mysql_error()); } //if } else { echo Nothing to insert; } //if ? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
Hey, Am not really used to using the JOIN in SQL so am a bit confused as to what kind of data I need to enter into this table: image_category_mapping table: - image_id - category_id for all of this to work... mind explaining a bit? Thanks! Ryan Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] web based chat app
umm sorry for interupting but RTFM / STFM? btw, if you dont need history you can write an webby irc client On 01/05/2008, paragasu [EMAIL PROTECTED] wrote: you build one. Thats the point of it wasn't it eh? A friend and I made a chat with jabber throught second life (the game) and a php webpage. interesting. i really wan't to try out your chat implementation. may i? i don't know how to integrate php with jabber since *i don't have much understanding *on how jabber works.. :).. may give me some idea..
Re: [PHP] mysql query and maximum characters in sql statement
Wouldn't using LOAD DATA INFILE be better than writing your own script? On 5/1/08, Jim Lucas [EMAIL PROTECTED] wrote: Jim Lucas wrote: Sanjeev N wrote: Hi, I have written a program which imports the tab delimited file and insert all the line from file to the mysql line by line. I am succeding in the above case. but problem with the above method is its taking to too much time while inserting into the database. The file's size will be more than 5000 lines. Then i tried to build a string of ; seperated queries. as follows for($i=1; $isizeof($array); $i++){ $insert_string .= insert into tablename (v1, v2. v6) values('$array[$i][1]', '$array[$i][2]'. '$array[$i][6]');; } if(!empty($insert_string)){ mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } Its throwing error saying check the manual for right syntax. After investigating in some sites i come to know that its problem of limitations in query size. I also tried with SET GLOBAL max_allowed_packet=3000; Then also its throwing the same error. Can anybody tell me how to fix this error and reduce the inserting time with a single statement instead of writing more insert statements You are probably looking for something like this. ?php if ( count($array) ) { $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; $data = array(); foreach ( $array AS $row ){ $row_clean = array_map('mysql_real_escape_string', $row); $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); } $insert_string = join(', ', $data); mysql_query($insert_string, $conn) or die(query failed : .mysql_errror()); } else { echo Nothing to insert; } ? That would work, but will probably result in a query string that is too long. I'll redo the above to fix that. ?php # How often do you want to insert?? $break_at = 100; # Initialize the counter $cnt = 0; # Initial insert string $insert_string = INSERT INTO tablename (v1, v2. v6) VALUES ; # if there is data, then process, otherwise skip it. if ( count($array) ) { $data = array(); # Loop through data foreach ( $array AS $row ) { $cnt++; # Clean the result data $row_clean = array_map('mysql_real_escape_string', $row); # Build data string and push it onto the data array. $data[] = ('{$row_clean[1]}', '{$row_clean[2]}',.'{$row_clean[6]}'); # Break and insert if we are at the break point if ( $cnt === $break_at ) { # Reset Counter $cnt = 0; # Run insert mysql_query($insert_string . join(', ', $data), $conn) or die(query failed : .mysql_error()); # Reset data array $data = array(); } //if } //foreach # This should take care of any extra that didn't get processed in the foreach if ( count($data) ) { # Insert remaining data mysql_query($insert_string . join(', ', $data), $conn) or die(query failed : .mysql_error()); } //if } else { echo Nothing to insert; } //if ? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check if any element of an array is not empty
At 3:36 PM -0500 4/30/08, afan pasalic wrote: hi, as a result of one calculation I'm receiving an array where elements could be 0 or date (as string -mm-dd hh:ii:ss). I have to check if any of elements of the array is date or if all elements of the array is 0? If I try array_sum($result) I'll get 0 no matter what (0 + $string = 0). I know I can do something like: foreach($result as $value) { if ($value !=0) { $alert = true; } } or if (in_array($result, '-')) { $alert = true; } but I was thinking if there is the function does that. thanks for any help. -afan You can create an empty array and check to see if the difference via array_diff. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Categories like wordpress
Ryan S wrote: Hey, Am not really used to using the JOIN in SQL so am a bit confused as to what kind of data I need to enter into this table: image_category_mapping table: - image_id - category_id It comes down to database normalization (http://en.wikipedia.org/wiki/Database_normalization). The idea behind database normalization is you only ever have one copy of the data, you don't have to update multiple tables to reflect a change. So you only store the image in the 'images' table: create table images ( image_id int auto_increment primary key, image_name text, .. ); For multiple categories to share a particular image, there needs to be a link between a category and an image. If you only ever want one image per category, you could put the image_id in the categories table: create table categories ( category_id int auto_increment primary key, category_name text, image_id int, . ); However the problem with that is if you want more than one image, instead of adding another field to the categories table: create table categories ( category_id int auto_increment primary key, category_name text, image_id int, image_id_two int, . ); which means if you want a category to have 3 images, you need another field and so on, so instead you create a separate table: create table category_images ( category_id int, image_id int ); which means you could have 10 images for that category and no db changes are necessary. So you create the image as normal (insert into images ...). Then when you link it to a particular category, you insert into the separate table: insert into category_images (category_id, image_id) values (.); This also means if you update the image (eg change the name or alt-value or whatever), it's automatically reflected for all categories. How do you get an image for the particular category? SELECT i.* from images i INNER JOIN category_images ci ON (image_id) WHERE category_id='X'; That will give you (multiple if necessary) images for that category. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php