Re: [PHP] Capturing the input of dynamic form fields (part II)
i think this query could be optimized by putting all the inserts in one query. something like this: $query = 'INSERT INTO test (test1, test2) VALUES '; foreach($_POST['test1'] as $i => $value ) { $query .= "('".$_POST['test1'][$i]."', '".$_POST['test2'][$i]."'), "; } $result = mysql_query( substr( $query, 0, -2 ) ); from the MySQL documents on optimizing inserts: "If you are inserting many rows from the same client at the same time, use multiple value lists INSERT statements. This is much faster (many times in some cases) than using separate INSERT statements. " or you could lock the table before the inserts and unlock it after... -- On Sun, 15 Jun 2003 22:13:13 +0200, Frank Keessen wrote (in message <[EMAIL PROTECTED]>): > Hi, > > Wow! Live = beautiful (or is it PHP??).. > > Any way: > > foreach($_POST['test1'] as $i => $Value) { >> $query = "INSERT INTO test (test1, test2) VALUES >> ('".$_POST['test1'][$i]."', '".$_POST['test2'][$i]."')"; >> $result = mysql_query($query); > > That one did the trick! > > Thanks James and Wouter for helping me out! > > Frank > - Original Message - > From: "esctoday.com | Wouter van Vliet" <[EMAIL PROTECTED]> > To: "Frank Keessen" <[EMAIL PROTECTED]>; "James Hicks" > <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Sunday, June 15, 2003 10:08 PM > Subject: RE: [PHP] Capturing the input of dynamic form fields (part II) > > >> First thing I notice as being at least a bit odd is this part: >> >> $nArraySize = count($_POST['test1']); >> $test1=$_POST['test1[]']; >> $test2=$_POST['test2[]']; >> >> what are you trying to do with that? .. What I'd expect it to look like is >> smth like: >> >> $nArraySize = count($_POST['test1']); >> $test1 = $_POST['test1']; >> $test2 = $_POST['test1']; >> >> but probably this: >> >> foreach($_POST['test1'] as $i => $Value) { >> $query = "INSERT INTO test (test1, test2) VALUES >> ('".$_POST['test1'][$i]."', '".$_POST['test2'][$i]."')"; >> $result = mysql_query($query); >> >> # and what else you'd want to do ... >> }; >> >> would just make even a little more sense .. some discussion could be about >> using $_POST['test1'][$i] to get the value again, or just using the $Value >> variable created by the foreach calls... >> >> -Oorspronkelijk bericht- >> Van: Frank Keessen [mailto:[EMAIL PROTECTED] >> Verzonden: zondag 15 juni 2003 21:44 >> Aan: Frank Keessen; James Hicks >> CC: [EMAIL PROTECTED] >> Onderwerp: Re: [PHP] Capturing the input of dynamic form fields (part >> II) >> >> >> Hi, >> >> Looks like the value's are not coming to the database.. Can you please all >> have a close look at my code because it's driving me NUTS! >> >> THANKS FOR YOUR HELP! >> >> > // open database connection >> $connection = mysql_connect($host, $user, $pass) or die ("Unable to >> connect!"); >> >> // select database >> mysql_select_db($db) or die ("Unable to select database!"); >> >> $_REQUEST["submit"]=isset($_REQUEST["submit"])?$_REQUEST["submit"]:""; >> if($_REQUEST['submit']!="") >> { >> $nArraySize = count($_POST['test1']); >> $test1=$_POST['test1[]']; >> $test2=$_POST['test2[]']; >> >> echo $nArraySize; >> for($i=0;$i<$nArraySize;$i++) { >> $query="INSERT INTO test (test1, test2) VALUES ('$test1[$i]', >> '$test2[$i]')"; >> $result = mysql_query($query); >> echo(mysql_error()."$query".mysql_affected_rows($result)); >> } >> >> } >> ?> >> > action=> >> > for ($i=1; $i<=2; $i++) >> { >> echo "# $i"; >> echo "# $i"; >> >> } >> >> ?> >> >> >> >> Regards, >> >> Frank >> >> >> - Original Message - >> From: "Frank Keessen" <[EMAIL PROTECTED]> >> To: "James Hicks" <[EMAIL PROTECTED]> >> Cc: <[EMAIL PROTECTED]> >> Sent: Sunday, June 15, 2003 8:59 PM >> Subject: Re: [PHP] Capturing the input of dynamic form fields (part II) >> >> >>> Hi James, >>> >>> Sorry to say; I've put your code in it but there are no error message's >>> displaying and there is no value inserted in the database... Any clue??? >>> >>> Regards, >>> >>> Frank >>> - Original Message - >>> From: "James Hicks" <[EMAIL PROTECTED]> >>> To: "Frank Keessen" <[EMAIL PROTECTED]> >>> Cc: <[EMAIL PROTECTED]> >>> Sent: Sunday, June 15, 2003 4:14 PM >>> Subject: Re: [PHP] Capturing the input of dynamic form fields (part II) >>> >>> Whenever I am having problems with SQL queries I always display the >> query >>> on the page with all the replaced variables so I can make sure that the >> query makes sense. If it passes the MySQL parser in my brain and still > doesn't work, I will copy the displayed query into the command line mysql >> monitor >>> (or phpmyadmin) and try the command manually to see what happens. I also found it easier to solve my SQL problems by not using "or die " >> and just displaying some information about the problem query. This way I >> know something is wrong if the third line of the echo is not at least 1. $query="INSERT INTO test (test1,
[PHP] two php installations
is there a way to install two phps on one apache server? want a stable php4 on my production site and a php5-dev to test on.. just use different virtualhosts, like php5.domain.com for the one with php5 installed. looked in the apache docs, seems like LoadModule cant be used inside , its a global var. thanx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: str_replace() problems actually *_replace() problems to be more accurate
take a look at the comments for the nl2br() functions, many nice examples for problems simular to this: http://no2.php.net/manual/en/function.nl2br.php On Mon, 16 Jun 2003 20:49:14 +0200, Thomas Bolioli wrote (in message <[EMAIL PROTECTED]>): > I am a perl/java/c++ programmer who is doing something in php and have > run accross something I am stumped with. I am trying to replace carriage > returns with or tags (p's in groups of two and br's for any > unmatched cr's). I have tried all of the *_replace() functions including > string_*, ereg_* and preg_*. None have worked the way they seem to > should. Note, I am a perl programmer and preg_replace() did not work > while a test perl script did. I have tried multiple forms of patterns > from "\r\n" to "\n" to "\r" to "/\r?\n/ei" (in the *reg_* functions). I > even took code verbatim from examples in the docs to no avail. I have > included the entire block of code (and mysql_dump output) since there is > something I have apparently not done right and it may not be in the > pattern matches. > Thanks in advance, > Tom > > > *The offending code:* > > }elseif($_REQUEST['add']){ > $desc = $_REQUEST['description']; > str_replace("\r\n\r\n", "", $desc); > str_replace("\r\n", "", $desc); > $result = mysql_query('INSERT INTO hr_listings > (title,description,location,end_date,posting_date) > VALUES("'.$_REQUEST['title'].'","'.$desc.'","'.$_REQUEST['location'].'","'.$_ > REQUEST['end_date'].'", > NOW())',$db) > or trigger_error("MySQL error nr ".mysql_errno().": ".mysql_error()); > > > *Output of mysql_dump showing the \r\n's going in* > INSERT INTO hr_listings VALUES > (15,'test',5,'2003-06-16','2003-09-11',NULL,'This > is one line\r\nThis is the next\r\n\r\nThis is another > paragraph\r\n\r\n'); > INSERT INTO hr_listings VALUES > (16,'test2',1,'2003-06-16','2004-09-11',NULL,'Thi > s is one line\r\nThis is the next\r\n\r\nThis is another > paragraph\r\n\r\n'); > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: refreshing fopen
PHP is server-side language, so this would be possible. Would go for meta tag or a javascript. On Tue, 17 Jun 2003 22:18:56 +0200, Bryan Koschmann - Gkt wrote (in message <[EMAIL PROTECTED]>): > Hello, > > I'm wondering what the best way to go about this would be. I will be > opening a URL that outputs a csv. This csv will change every few minutes, > and I would like it to be refreshed on my page. I know I can use a meta > refresh, but the time will vary from 1-5 minutes, so a meta refresh will > have a gap where it won't be update. > > Is there someway to hold it open, and when it changes refresh itself? This > is all on a LAN, so the traffic isn't that big of a deal. > > > Thanks, > > Bryan > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Calling c function from php
if you want to integrate the c/c++ codes in php you can use the build_skel that follows php to do this. write: ./build_skel --extname=calculate --proto=/path/to/calculate.proto --assign-params where extname is the extension name and proto is a file containing the prototypes of the functions to create. something like this: void calc_over( double value ) double calc_under( double value, double type ) and so on... im sure there are howtos and such on the net, so i dont botter writing it all down. Terje On Wed, 18 Jun 2003 16:56:52 +0200, Cpt John W. Holmes wrote (in message <[EMAIL PROTECTED]>): >> Anyway, can any make a suggestion on how to connect to a c function from >> a php app? >> >> I have to connect to a sales tax calculation software. The function >> is being written for me but I have to figure how to call it - get the >> variable - and use it again in my php app. >> >> I've been told there's an api or module on the php site with >> documentation that I am trying to research. >> >> Has anybody ever done this ? > > I'm sure you could compile it into PHP somehow, if you wanted to go that > route. I can't help you there, though. > > Or, you could just compile your C function into a stand-alone program and > call it through exec(), passing the parameters it needs and then retrieving > the output. > > Why not just "port" the C code over to PHP?? > > ---John Holmes... > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Help with my code
To echo multiple lines you have to write echo << ... .. END; and in the beginning you have if( $action ) { if... elseif .. elseif.. if( $action ) { => why this? you have already checked if $action is true earlier... } } (nb! posting the what the error is might help solve a problem) On Wed, 18 Jun 2003 17:09:18 +0200, Mark Clarkstone wrote (in message <[EMAIL PROTECTED]>): > why won't this write? > > require ("config.php"); > if ($action) { > > If ($name=="") { > echo "Form Error >> No Name"; > echo "$errorbk"; > } > else if ($email=="") { > echo "Form Erorr >> No e-mail"; > echo "$errorbk"; > } > else if ($input=="") { > echo "Form Error >> No Comment found"; > echo "$errorbk"; > } > else if ($wb=="1") { > mail($webemail, $subject, $input); > } > if ($action) { > $data = "$name\n$email\n$input"; > $fp = fopen("messages.txt",'a'); > $fw = fwrite($fp,$data,$subject); > fclose($fp); > echo "Thank you"; > } > } > else if (!$action) { > echo " > > > > > > $pagetitle > > > > > > Commentie Version > 1.0 > Your Name > > Your E-mail style='font-family: Tahoma; font-size: 10pt'> > Your msg / comment > > > e-mail & save > > Yes > No > > > > > style='font-size: 10pt; font-family: Tahoma'> > > > > > "; > } > ?> > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Help with my code
hehe.. know, i seem to write it a little fast.. it a _long_ time since ive use this notation.. :) im gonna check it to be sure next time.. On Wed, 18 Jun 2003 17:45:26 +0200, Lars Torben Wilson wrote (in message <[EMAIL PROTECTED]>): > Organization: > MIME-version: 1.0 > X-Mailer: Ximian Evolution 1.2.3 > Content-type: text/plain > Content-transfer-encoding: 7BIT > References: <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > Subject: Re: [PHP] Re: Help with my code > From: [EMAIL PROTECTED] (Lars Torben Wilson) > > On Wed, 2003-06-18 at 08:23, Terje Torkelsen wrote: >> To echo multiple lines you have to write >> >> echo <<> >> >> >> >> >> >> ... >> .. >> >> END; > > No offense, but this is completely false. Double-quotes will work just > fine. > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: two php installations
ok.. thanx ive looked at it a little, and havent tested this yet as my server "broke" down recently. but i thought this might work: the php4 and php5 modules have different modules name, if i dont remember totaly wrong, so writing LoadModule php4_module modules/libphp4.so LoadModule php5_module modules/libphp5.so should work. Then by changing the mime type of php5 to "application/x-httpd-php5" ( in the main/php.h file at line 228 this is defined ) on can add to different virtualhost with different mime types: DocumentRoot /var/www/html ServerName www.domain.com AddType application/x-httpd-php .php #php4 DocumentRoot /var/www/html ServerName www.domain.com AddType application/x-httpd-php5 .php #php5 but then again i havent tested this, its just a thought i was gonna try as soon as i get my server online again... Terje On Tue, 17 Jun 2003 3:23:08 +0200, Dvdmandt wrote (in message <[EMAIL PROTECTED]>): > Hehe, ok... I can't even count the number of servers I use at different > ports... But I prefer to use the one on port 80... > // DvDmanDT > > <[EMAIL PROTECTED]> skrev i meddelandet > news:[EMAIL PROTECTED] >> hmm to spare the pain i run another instance of apache on a different >> port , one runs php4.3 one runs php5 :D >>> If you bug the PHP team some, they might rename the PHP5 module so you >>> can use both... I have PHP3, 4 and 5 (can someone please give me a >>> working binary PHP1 and PHP2 for windows? PLEASE!!!) installed and >>> working on the same server... Simply use the CGI version... But server >>> gets slower and slower on every request (well, maybe not _every_ >>> request but)... >>> >>> // DvDmanDT >>> "Terje Torkelsen" <[EMAIL PROTECTED]> skrev i meddelandet >>> news:[EMAIL PROTECTED] >>>> is there a way to install two phps on one apache server? want a stable >>> php4 >>>> on my production site and a php5-dev to test on.. just use different >>>> virtualhosts, like php5.domain.com for the one with php5 installed. >>>> looked >>> in >>>> the apache docs, seems like LoadModule cant be used inside >>>> , >>> its >>>> a global var. >>>> >>>> thanx >>>> >>> >>> >>> >>> -- >>> 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