[PHP] Re: Newbie Question about Conditionals
Matty Sarro wrote: Hey all! This is probably my second post on the list, so please be gentle. Right now I am running through the Heads First PHP and MySQL book from O'Reilly. It's been quite enjoyable so far, but I have some questions about some of the code they're using in one of the chapters. Basically the code is retreiving rows from a DB, and I'm just not getting the explanation of how it works. Here's the code: $result=mysqli_query($dbc,$query) while($row=mysqli_fetch_array($result)){ echo $row['first_name'].' '.$row['last_name'].' : '. $row['email'] . 'br /'; } Now, I know what it does, but I don't understand how the conditional statement in the while loop works. Isn't an assignment operation always going to result in a true condition? Even if mysqli_fetch_array($result) returned empty values (or null) wouldn't the actual assignment to $row still be considered a true statement? I would have sworn that assignment operations ALWAYS equated to true if used in conditional operations. Please help explain! :) Thanks so much! -Matty Others have explained in detail, but I will tell you why you and many beginners may have been confused by this. On this list as well as in other help sites for PHP, beginners post code that contains something like this, and wonder why it always echoes TRUE: $value = 'bob'; if($value = 'test') { echo 'TRUE'; } else { echo 'FALSE'; } They normally get an answer such as: You need to use == for comparison, = is an assignment operator and the assignment will always evaluate to true. Well, this is true for this assignment because the non-empty string 'test' evaluates to true. But without explanation it may sound as though ANY assignment will evaluate to true just because the actual assignment itself was successful. This is obviously not the case. This echoes FALSE: $value = 'bob'; if($value = '') { echo 'TRUE'; } else { echo 'FALSE'; } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: newbie question about storing big5 codes into mysql-5.0.24a
Man-wai Chang wrote: create table temp ( big5 char(2) ) character set big5 collate big5_bin; insert into temp ( big5 ) values ( 0x9f54 ); insert into temp ( big5 ) values ( 0x9f53 ); The 2nd query will report duplicated key. How should I fix the problem? What does this has to do with PHP? First of all I don't see any PHP code, and second this is an error in your SQL query, so you should be on the MySQL list. I used mysqli_query() to send the SQL. How could I make it work? That really doesn't make this question PHP-related. You really do need to ask on a MySQL mailing list. This has nothing to do with PHP, and you're more likely to get a useful answer from a MySQL-specific list. If you really want to try and justify asking this question here, try the queries in the command-line MySQL client. If it works there but not through mysqli_query() then you might have a case for asking here. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: newbie question about storing big5 codes into mysql-5.0.24a
queries in the command-line MySQL client. If it works there but not through mysqli_query() then you might have a case for asking here. For the 13081 chinese alphabets I tried, only 1 one failed, and it's 0x9f54. mysqli_query() should have escaped the string for me. So ... I suppose most PHP programmers are also experts in MySQL (they are basically tied). SO I tried my luck here. :) -- .~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Ubuntu 6.10) Linux 2.6.20.4 ^ ^ 21:24:01 up 1 day 8:36 0 users load average: 1.00 1.02 1.00 news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: newbie question about storing big5 codes into mysql-5.0.24a
Man-wai Chang wrote: queries in the command-line MySQL client. If it works there but not through mysqli_query() then you might have a case for asking here. For the 13081 chinese alphabets I tried, only 1 one failed, and it's 0x9f54. mysqli_query() should have escaped the string for me. mysqli_query() doesn't escape anything for you - your assumption that it *should* is WRONG. try this: http://php.net/manual/en/function.mysqli-real-escape-string.php So ... I suppose most PHP programmers are also experts in MySQL (they are basically tied). incorrect supposition. most php programmers have experience using RDBMs because of the dynamic nature of the websystems they build. mysql and php and not tied at all .. they just happen to be used together frequently. SO I tried my luck here. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: newbie question about storing big5 codes into mysql-5.0.24a
create table temp ( big5 char(2) ) character set big5 collate big5_bin; insert into temp ( big5 ) values ( 0x9f54 ); insert into temp ( big5 ) values ( 0x9f53 ); The 2nd query will report duplicated key. How should I fix the problem? What does this has to do with PHP? First of all I don't see any PHP code, and second this is an error in your SQL query, so you should be on the MySQL list. I used mysqli_query() to send the SQL. How could I make it work? -- .~. Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Ubuntu 6.10) Linux 2.6.20.4 ^ ^ 14:43:01 up 1 day 1:55 0 users load average: 1.01 1.02 1.00 news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
Satyam wrote: for ($x=0;$x1000;$x++) { echo ' trtdX is ' , $x , '/td/tr'; } This seems to be a hair faster. I extended the test to 1 requests (still concurrency 10) to make the test a little more reproducible: echo str,var,str did 604.65 requests a second where trtd?= $x ?/td/tr did 599.63 requests a second. I also tried echo str . var . str, and it came in at about 584.55 requests a second. printf(str %i str,var) came out at 547.01 requests a second and printf(str %s str,var) was only 452.03 requests a second. Can you try and time that one so we have comparable results? This one should be second best: for ($x=0;$x1000;$x++) { echo trtdX is $x/td/tr; } Approximately 330 (?!) requests a second for that one. Back again to what would be 'longer', well, in your example, the whole header, up to the loop itself should be faster if sent out of PHP. Likewise, you could echo $buffer right after the loop, drop out of PHP and send the footer as plain HTML. This, of course, is harder to time since it happens only once. I admit though that I did time the options I listed and on the 'dropping in and out of PHP' I'm relying on the PHP manual ( see http://www.php.net/manual/en/language.basic-syntax.php, the first paragraph after the examples) and the source of the lexical scanner, which supports that, though your numbers do contradict it. Interesting. I'm not sure that my results would count as contradictory - I'm running APC which would likely throw performance related numbers out of whack as compared to out-of-the-box PHP. Because of that, I wouldn't recommend anyone take my numbers too seriously - they're just an example taken from my server: 1.8 GHz SMP/1G/RAID5/Linux 2.6.17.7/Apache 2.2.3/PHP 5.1.6/APC 3.0.12p2. Anyone else's results would probably vary widely. jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
How bored am I? This bored: http://dev.stut.net/phpspeed/ Server is running PHP 5.1.2 (really should upgrade that) with no caches of any sort. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
At 4:56 PM +0100 9/11/06, Stut wrote: How bored am I? This bored: http://dev.stut.net/phpspeed/ Server is running PHP 5.1.2 (really should upgrade that) with no caches of any sort. -Stut Which begs the question, does it make much of a difference? (not you being bored, but the rather speed concers). With all the things out there that can slow your browsers reaction time in presenting some result, does a couple of seconds count much in the over all scheme of things? I know, purest will say that they want to make whatever they do as fast as possible, but is that time to make it faster be better spent elsewhere? We used to have to worry about the size of our strings, but now we can place the kjv of the bible in one. So, what's the point of counting characters in strings now? I suspect at some point, probably soon, speed isn't going to matter much. Opinions? 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] Re: Newbie question about ?= ?
I admit I'm totally surprised about the buffered results. Nevertheless, may I sugest you add the following to the series of tests?: h3Using line-by-line single-quoted echobr/with comma separated arguments/h3 ?php $start = mt(); print 'table style=display:none; id=table2a'; for ($x = 0; $x $iterations; $x++) { echo 'trtdX is/tdtd',$x,'/td/tr'; } print '/table'; $duration = mt() - $start; print 'pTook '.number_format($duration, 4).' seconds/p'; ? praquo; a id=table2alink href=# onclick=document.getElementById('table2a').style.display='block'; document.getElementById('table2alink').style.display='none';return false; Reveal output/a/p There seems to be one thing rarely anybody remembers, echo admits multiple arguments, and as the numbers will show, (or at least they do in my machine), they are the second best option. Satyam - Original Message - From: Stut [EMAIL PROTECTED] To: Jon Anderson [EMAIL PROTECTED] Cc: Satyam [EMAIL PROTECTED]; php-general@lists.php.net Sent: Monday, September 11, 2006 5:56 PM Subject: Re: [PHP] Re: Newbie question about ?= ? How bored am I? This bored: http://dev.stut.net/phpspeed/ Server is running PHP 5.1.2 (really should upgrade that) with no caches of any sort. -Stut -- 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: Newbie question about ?= ?
Satyam wrote: I admit I'm totally surprised about the buffered results. Nevertheless, may I sugest you add the following to the series of tests?: h3Using line-by-line single-quoted echobr/with comma separated arguments/h3 snip There seems to be one thing rarely anybody remembers, echo admits multiple arguments, and as the numbers will show, (or at least they do in my machine), they are the second best option. Done, but again it doesn't seem to make any significant difference to the performance. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
tedd wrote: At 4:56 PM +0100 9/11/06, Stut wrote: How bored am I? This bored: http://dev.stut.net/phpspeed/ Server is running PHP 5.1.2 (really should upgrade that) with no caches of any sort. -Stut Which begs the question, does it make much of a difference? (not you being bored, but the rather speed concers). With all the things out there that can slow your browsers reaction time in presenting some result, does a couple of seconds count much in the over all scheme of things? I know, purest will say that they want to make whatever they do as fast as possible, but is that time to make it faster be better spent elsewhere? We used to have to worry about the size of our strings, but now we can place the kjv of the bible in one. So, what's the point of counting characters in strings now? I suspect at some point, probably soon, speed isn't going to matter much. Opinions? I would have to agree. Having watched the server CPU load while playing with this test script it would appear that the performance can be skewed a lot more by that than by the method you use for squidging out the output. As a curiosity I've also added a test using ?php print $x; ? and bizarrely that appears to be slightly faster than ?=$x?. Weird. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
Jon Anderson wrote: Stut wrote: How bored am I? This bored: http://dev.stut.net/phpspeed/ Server is running PHP 5.1.2 (really should upgrade that) with no caches of any sort. Just looking through the source, could you try changing the first example to put the output all on one line? It's the only one that does the row output on multiple indented lines - I'm kind of curious what effect (if any) that has on the results. Done. Doesn't seem to make a difference - I didn't expect it to. I also tried this on my own server. With the opcode cache, the results seem to be the inverse of yours without. I would have been surprised if an opcode cache had made a huge difference. I don't think the Zend Engine is intelligent enough to compile the various different tests to the same set of opcodes - but I could be wrong. I'm still quite new to the PHP internals. Also, with either server, the first three results seem to vary wildly, but the last two always seem to come out the same. I'm not sure why that is... As I said in another post, the performance varies wildly with the load on the server. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
- Original Message - From: Stut [EMAIL PROTECTED] To: Satyam [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Monday, September 11, 2006 6:32 PM Subject: Re: [PHP] Re: Newbie question about ?= ? Satyam wrote: I admit I'm totally surprised about the buffered results. Nevertheless, may I sugest you add the following to the series of tests?: h3Using line-by-line single-quoted echobr/with comma separated arguments/h3 snip There seems to be one thing rarely anybody remembers, echo admits multiple arguments, and as the numbers will show, (or at least they do in my machine), they are the second best option. Done, but again it doesn't seem to make any significant difference to the performance. -Stut When I run those tests locally, the numbers are totally different and the performance of one over the other comes out far clearer. I can only assume that the numbers in the test run in a remote server are so much influenced by the ability of the server to push out the characters into the output stream that the processing time itself is of very little relevance. This table shows the numbers for the different tests as run on my machine, locally (where output streaming is irrelevant) and run from your site: Using ?=$x?Took 0.2801 secondsTook 3.5937 seconds Using ?php print $x; ?Took 0.3286 secondsTook 5.2654 seconds Using line-by-line single-quoted print:Took 0.1215 secondsTook 3.2256 seconds Using line-by-line single-quoted echo with comma separated argumentsTook 0.2542 secondsTook 3.2220 seconds Using line-by-line double-quoted print Took 0.1782 secondsTook 3.3129 seconds Using buffered single-quoted printTook 0.0277 secondsTook 3.3077 seconds Using buffered double-quoted printTook 0.2038 seconds Took 3.3012 seconds It would seem that it takes about 3 seconds to push those bytes into the network, the actual processing times get completely masked behind a simple glitch in the throughput of the communication line. While the differences on the rightmost column (except for the second one, which is way off) are no more than 5%, in the middle column the differences are up to 10 to 1. But then there is that second row, which is so much higher and it is so in both columns. Unfortunately, I cannot make much sense about all this. I don't get it. Nevertheless, something it is clear is that buffering all the output first and then pushing it out all at once seems to beat them all, specially using single quoted strings. Run locally, the differences are amazing! Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
At 5:36 PM +0100 9/11/06, Stut wrote: tedd wrote: Opinions? I would have to agree. Having watched the server CPU load while playing with this test script it would appear that the performance can be skewed a lot more by that than by the method you use for squidging out the output. As a curiosity I've also added a test using ?php print $x; ? and bizarrely that appears to be slightly faster than ?=$x?. Weird. My guess would be that it's in the interpreter -- the look-up for ? as compared to ?php may be delayed because of checking for the short-tag option-on, or something similar. But, I admittedly don't know. However, I strongly suspect that drawing to the screen will take longer than executing any = or print statement anyway. So regardless of the time saved in computation, the delivery would appear identical. It reminds me of the hurry-up and wait saying we had in the Army some 50 years back. 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
[PHP] Re: Newbie question about ?= ?
Mike Borrelli wrote: Good day, While I've been using php for more than a little while now, I've never understood why the use of the ?= ...? short tag is noted to be avoided. Or rather, I understand that there's an option to disable it, and that's why it's noted in this way, but I don't understand why it's disabled? What's gained by writing ?php echo some_function(); ? over ?= some_function(); ? Thanks in advance. Cheers, Mike Structurally, there is a far better way to compile your html pages. This approach is easier to design and debug and it is faster since it sends one complete packet instead of one for every short tag. And, it saves using ob_start() and ob_flush(). Consider: $report= ''; $report .= function() [or whatever] . repeat as necessary to assemble your complete page. Then simply echo $report; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
- Original Message - From: Al [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Sunday, September 10, 2006 5:52 PM Subject: [PHP] Re: Newbie question about ?= ? Mike Borrelli wrote: Good day, While I've been using php for more than a little while now, I've never understood why the use of the ?= ...? short tag is noted to be avoided. Or rather, I understand that there's an option to disable it, and that's why it's noted in this way, but I don't understand why it's disabled? What's gained by writing ?php echo some_function(); ? over ?= some_function(); ? Thanks in advance. Cheers, Mike Structurally, there is a far better way to compile your html pages. This approach is easier to design and debug and it is faster since it sends one complete packet instead of one for every short tag. And, it saves using ob_start() and ob_flush(). Consider: $report= ''; $report .= function() [or whatever] . repeat as necessary to assemble your complete page. Then simply echo $report; Actually, in my experience, that is not the case, my e-mail from more than a year ago must be somewhere there in the archives, but what you sugest is not the fastest. The fastest is to escape out of php (with a ? ) for the longer invariable parts of immutable HTML. Stepping out from PHP and in again is handled by the lexical scanner, it doesn't even reach the parser level so, for all effects, the PHP interpreter is basically frozen at the point before the ? was found. For the sake of completeness, the ? is translated as a ; for the parser so it ends any statement that could have been left open, but it does not bother the parser at all for all the rest of the characters found until a ?php tag (or equivalent) is found. If the lexer didn't issue a ; for a ?, the following code would be valid: echo 'This ' , ? is ?php 'not valid'; For the variable parts, the best is to issue as little echos as possible with its arguments separated by commas, not with dots. Most people don't realize that echo taks a list of arguments, a list separated by commas. Thus, in the ratings, from best to worst, it goes: echo 'p' , $something, '/p'; echo p$something/p echo 'p' . $something . '/p'; echo 'p'; echo $something; echo '/p'; The reason for this is that generating a single string either from variable interpolation as in the second case or by concatenating the arguments, as in the third, requires a lot of memory handling for the strings and its intermediate and final results. Some of it might be delayed until the page is served so the time the garbage collector takes to clean it up might not be fully reflected in the processing time of a single page, but it does affect the overall throughput of the server. Notice also that I have used single quotes whenever possible, which is slightly faster since the parser has much less to look for within it. Finally, the first option is the fastest just as a C++ iostream or a Java StringBuffer are faster than plain strings: since you know you will only append to the end of them, the characters echoed go into a much more efficient character buffer instead of a more complex string which has to be available for all sorts of string operations. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
Al wrote: Structurally, there is a far better way to compile your html pages. This approach is easier to design and debug and it is faster since it sends one complete packet instead of one for every short tag. And, it saves using ob_start() and ob_flush(). Consider: $report= ''; $report .= function() [or whatever] . repeat as necessary to assemble your complete page. Then simply echo $report; I thought I'd look into this, because I'm a bit of a performance nut - I like my code to run as fast as possible at all times. I wrote up a quick buffer v.s. direct benchmark for this, and the winner is clear: direct output is much faster. (If my example below isn't what you meant, please let me know. I'm always happy to hear new ways to improve my code.) Best of 3 runs with apache bench (concurrency 10, 1000 requests total): Direct output: 582 requests a second Buffer var: 286 requests a second I believe the margin would get wider with real-world usage, as the buffer variable would increase in size. My test code is copied below. jon --- Direct output: testecho.php --- html head style type=text/wastespacetosimulateastylesheet style1 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style2 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style3 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style4 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } /style /head bodytable ?php for ($x=0;$x1000;$x++) { ? trtdX is ?= $x ?/td/tr ?php } ? /table/body /html --- Buffered output: testbuffer.php --- ?php $buffer = ' html head style type=text/wastespacetosimulateastylesheet style1 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style2 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style3 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style4 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } /style /head bodytable'; for ($x=0;$x1000;$x++) { $buffer .= trtdX is $x/td/tr; } $buffer .= '/table/body /html'; echo $buffer; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie question about ?= ?
- Original Message - From: Jon Anderson [EMAIL PROTECTED] To: php-general@lists.php.net Cc: Al [EMAIL PROTECTED] Sent: Sunday, September 10, 2006 9:16 PM Subject: Re: [PHP] Re: Newbie question about ?= ? Al wrote: Structurally, there is a far better way to compile your html pages. This approach is easier to design and debug and it is faster since it sends one complete packet instead of one for every short tag. And, it saves using ob_start() and ob_flush(). Consider: $report= ''; $report .= function() [or whatever] . repeat as necessary to assemble your complete page. Then simply echo $report; I thought I'd look into this, because I'm a bit of a performance nut - I like my code to run as fast as possible at all times. I wrote up a quick buffer v.s. direct benchmark for this, and the winner is clear: direct output is much faster. (If my example below isn't what you meant, please let me know. I'm always happy to hear new ways to improve my code.) Best of 3 runs with apache bench (concurrency 10, 1000 requests total): Direct output: 582 requests a second Buffer var: 286 requests a second I believe the margin would get wider with real-world usage, as the buffer variable would increase in size. My test code is copied below. jon --- Direct output: testecho.php --- html head style type=text/wastespacetosimulateastylesheet style1 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style2 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style3 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style4 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } /style /head bodytable ?php for ($x=0;$x1000;$x++) { ? trtdX is ?= $x ?/td/tr ?php } ? /table/body /html --- Buffered output: testbuffer.php --- ?php $buffer = ' html head style type=text/wastespacetosimulateastylesheet style1 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style2 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style3 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } style4 { a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; } /style /head bodytable'; for ($x=0;$x1000;$x++) { $buffer .= trtdX is $x/td/tr; } $buffer .= '/table/body /html'; echo $buffer; ? -- In my message I was careful to mention that stepping in and out of PHP was good 'for the longer invariable parts of immutable HTML'. What could be considered 'longer' is certainly a matter discussion, your results prove that this is not long enough. Notice that when the parser finds the '?=', it converts it into the equivalent of ? echo, thus, though the echo is not explicitly there, from the parser on is as if it were. Then, since you have an echo, why not use it for all of the output?The equivalent to what I showed as the second best, which would be the first best with 'shorter' strings would be the following: for ($x=0;$x1000;$x++) { echo ' trtdX is ' , $x , '/td/tr'; } Can you try and time that one so we have comparable results? This one should be second best: for ($x=0;$x1000;$x++) { echo trtdX is $x/td/tr; } Back again to what would be 'longer', well, in your example, the whole header, up to the loop itself should be faster if sent out of PHP. Likewise, you could echo $buffer right after the loop, drop out of PHP and send the footer as plain HTML. This, of course, is harder to time since it happens only once. I admit though that I did time the options I listed and on the 'dropping in and out of PHP' I'm relying on the PHP manual ( see http://www.php.net/manual/en/language.basic-syntax.php, the first paragraph after the examples) and the source of the lexical scanner, which supports that, though your numbers do contradict it. Interesting. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie question about operators
Thanks Ligaya Ligaya Turmelle [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] it is refering to the associative array, specifically the $key = $value . Note here (http://www.php.net/manual/en/language.types.array.php). Respectfully, Ligaya Turmelle Gabe [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Looking at the code below, what exactly is happening with the $name=$value part? I looked in the PHP online documentation and I can't find that operator. What is it doing exactly and what is it called? foreach ($some_array as $name=$value) { ... some code ... } Thanks alot! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie question about operators
it is refering to the associative array, specifically the $key = $value . Note here (http://www.php.net/manual/en/language.types.array.php). Respectfully, Ligaya Turmelle Gabe [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Looking at the code below, what exactly is happening with the $name=$value part? I looked in the PHP online documentation and I can't find that operator. What is it doing exactly and what is it called? foreach ($some_array as $name=$value) { ... some code ... } Thanks alot! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: newbie question about scope
things to check.. check the register_globals flag in php.ini - you can also set this using ini_set() Check the short_open_tags are either on/off - again this chan be changes in ini_set() pete News.Comcast.Giganews.Com wrote: I am an experienced web developer who is just getting into php. I have had a php project fall into my lap and wanted a little advice. Here is the scoop: A client moved their site from a server (unknown details) to a hosting facility (php 4.3.2). Now none of the scripts work. I have guessed that they are coming from an earlier version of apache/php. Anyway it appears that whoever created the site in the first place did not believe in scoping variables. Now any variable that is not properly scoped will not be read by the server. I know I can simply scope all of the variables, but I was hoping there may be an easier way. Also, how bad is the _REQUEST scope I read that it could not be trusted, however the previous developer created the app in such a way that several places a variable could be _GET or _POST. I apologize for the rambling and possible incoherency of this message, I am a bit tired. Matthew PS. How do you scope queries? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie question about SQL result formatting
see nl2br(). You might also want to convert spaces to nbsp;'s On Fri, 9 Aug 2002, Kristoffer Strom wrote: Ok, this is totally newbie but I just started messing around with PHP after programming IBM's NetData for a while. My first big problem I haven't been able to solve myself is how to format the result of an SQL query into HTML code. In the (MySQL) database, I have one field for very long texts. One test entry looks like this: -- test test test -- But when printing the result, even with HTMLENTITIES and HTMLSPECIALCHARS, just looks like: - test test test - How do I convert the result to HTML code, I especially want the linebreaks!! The answer is probably very simple /Kris -- 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] Re: Newbie question about SQL result formatting
There we go :) If there's any consolation, you just helped NataliePortman.com become a better website :) Thx /Kris Philip Hallstrom [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... see nl2br(). You might also want to convert spaces to nbsp;'s On Fri, 9 Aug 2002, Kristoffer Strom wrote: Ok, this is totally newbie but I just started messing around with PHP after programming IBM's NetData for a while. My first big problem I haven't been able to solve myself is how to format the result of an SQL query into HTML code. In the (MySQL) database, I have one field for very long texts. One test entry looks like this: -- test test test -- But when printing the result, even with HTMLENTITIES and HTMLSPECIALCHARS, just looks like: - test test test - How do I convert the result to HTML code, I especially want the linebreaks!! The answer is probably very simple /Kris -- 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] Re: Newbie question about PHP and Oracle
Hi, I think you mean hwo u can get the data into an array well here is an example : $query = select ...; $stmt = ociparse( $connectionhandle, $query ); if( ociexecute( $stmt, OCI_DEFAULT ) ){ ocifetchinto( $stmt, $row, OCI_ASSOC+OCI_RETURN_NULLS ); } and now you got 1 resultset in an associative array called $row. take a look at the oci-functions in the manual for the different flags u can set. regards markus mirsberger Michael Sweeney [EMAIL PROTECTED] schrieb im Newsbeitrag [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... a VERY newbie question, just how do I get data into a listbox? In mysql it was pretty easy with mysql_fetch_row, but for oracle I am totally lost. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie: Question about filesize()
You also seem to have an extra equals. Your loop should read: while (false != ($file=readdir($handle))){ It should come up as an error, but I'm not sure. Ben Manuel Ritsch wrote: Hello There I'm new to PHP and trying to code a function that reads all teh files out of a directory and printing out a link and the filesize, but it seems that the filesize() function doesn't work, here's the code so far: $handle = opendir ('images'); echo Files:brbr; while (false !== ($file = readdir ($handle))) { if($file != . $file != ..) { $file_s = filesize($file); echo a href=images/$file$file/a Filesize: $file_sbr; } } closedir($handle); and the output is somethingl ike this: Files: button_test_04.gif Filesize: button_test_03-down.gif Filesize: lilextras_01.gif Filesize: (and so on)... You see, there's no Filesize and I don't know why, please help me -- manu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Newbie: Question about filesize()
that should be okay - it's to make sure that it is exactly equal to (as opposed to equates to be equal to) eg (0 === false) = false (0 == false) = true -Original Message- From: Ben Crawford [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 07, 2002 2:28 AM To: [EMAIL PROTECTED] Subject: [PHP] Re: Newbie: Question about filesize() You also seem to have an extra equals. Your loop should read: while (false != ($file=readdir($handle))){ It should come up as an error, but I'm not sure. Ben Manuel Ritsch wrote: Hello There I'm new to PHP and trying to code a function that reads all teh files out of a directory and printing out a link and the filesize, but it seems that the filesize() function doesn't work, here's the code so far: $handle = opendir ('images'); echo Files:brbr; while (false !== ($file = readdir ($handle))) { if($file != . $file != ..) { $file_s = filesize($file); echo a href=images/$file$file/a Filesize: $file_sbr; } } closedir($handle); and the output is somethingl ike this: Files: button_test_04.gif Filesize: button_test_03-down.gif Filesize: lilextras_01.gif Filesize: (and so on)... You see, there's no Filesize and I don't know why, please help me -- manu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie: Question about filesize()
At 10:27 AM 2/6/2002 -0500, Ben Crawford wrote: You also seem to have an extra equals. Your loop should read: while (false != ($file=readdir($handle))){ I think you could eliminate the false != in the while condition... It should be just the same if you write while (($file = readdir($handle))) right? -Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie: Question about filesize()
On Wed, 2002-02-06 at 07:27, Ben Crawford wrote: You also seem to have an extra equals. Your loop should read: while (false != ($file=readdir($handle))){ It should come up as an error, but I'm not sure. Ben No, that's the 'identical' operator, which returns true when its operands are both equalivalent and of the same type: http://www.php.net/manual/en/language.operators.comparison.php Cheers, Torben -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie: Question about filesize()
On Wed, 2002-02-06 at 15:33, Jeff Sheltren wrote: At 10:27 AM 2/6/2002 -0500, Ben Crawford wrote: You also seem to have an extra equals. Your loop should read: while (false != ($file=readdir($handle))){ I think you could eliminate the false != in the while condition... It should be just the same if you write while (($file = readdir($handle))) right? -Jeff Wrong, actually. If you have any files in that directory which have names which would evaluate as false in PHP, then your way will fail on them and you'll get a truncated directory listing. Do 'touch 0' in a directory and give it a shot; you'll see what I mean. However, the original example does the same thing, since it only checks whether the result of the readdir() evaluates to FALSE, not whether it actually is a boolean FALSE value. The correct way to do this is: while (FALSE !== ($file = readdir($handle))) { . . . } Note the !== instead of !=. Hope this helps, Torben -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie: Question about filesize()
Manuel Ritsch [EMAIL PROTECTED] wrote: $file_s = filesize($file); you want $file_s = filesize(images/$file). jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]