Re: [PHP] databases, loops and tables oh my...
Jason Gerfen wrote: Not sure about this one, I am trying to execute a SQL query to retrieve records then loop over the records and display X amount per line. Any X ammount of what per 'line'? db records (or elelphants)? and by line do you mean 'html table row'? assuming I got that correct, check my comments below (hopefully it's understandable): help is appreciated. $sql = @mysql_query( SELECT * FROM subnets, $db ); $num = @mysql_num_rows( $sql ); $subnets .= table width=\100%\trtd bgcolor=\#C10202\ class=\fntTR\ colspan=\$num\Subnets and global parameters for each/td/trtr; $i = 1; // add the following line here: $numPerRow = 3; // number of records to show per table row. while( $list = @mysql_fetch_array( $sql ) ) { list( $id, $subnet, $mask, $dns01, $dns02, $router, $vlan, $scope, $range1, $range2, $vlan ) = $list; // and replace this if(): if( $i % 2 == 0 ) { $tr = /trtr; } // with this: $tr = ($i % $numPerRow) ? /trtr : ; if( $scope == no ) { $range1 = NULL; $range2 = NULL; } $subnets .= td valign=\top\ valign=\center\ table cellspacing=\3\ border=\0\ trtd colspan=\2\ align=\center\bu$vlan/u/b/td/tr trtdbSubnet:/b/tdtd$subnet/td/tr trtdbMask:/b/tdtd$mask/td/tr trtdbDNS:/b/tdtd$dns01/td/tr trtdbDNS:/b/tdtd$dns02/td/tr trtdbGateway:/b/tdtd$router/td/tr trtdbVlan:/b/tdtd$vlan/td/tr trtdbScope:/b/tdtd$range1nbsp;-nbsp;$range2/td/tr /table/td . $tr; $i++; } $subnets .= /tr/table; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops performance
On Sat, 2004-08-21 at 12:17, Xongoo!com: Central unit wrote: Holla, Maybe someone knows how to improve for loops performance? When generating 1000's of pages, it oads in 10-20 seconds. Maybe there is some solution I don't know about? Give us an example of your for loop that is having efficiency problems. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops performance
Xongoo!com: Central unit wrote: Holla, Maybe someone knows how to improve for loops performance? When generating 1000's of pages, it oads in 10-20 seconds. Maybe there is some solution I don't know about? prey what is your algorithm? Thanks! -- Tadas Talaikis [EMAIL PROTECTED] http://www.xongoo.com -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 128 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops performance
Here's: for ($c=1; $c$numpages; $c++){ echo a href=page$c.html$c/a | ; } When it generates 1-10, it is normal 0.05 s, but often I need more than 1000, so when generating 100's - it is 0.5-1.5 sec., when more than 1000 - 10+ s. I am thinking on running sopme sort of: 1) generate code of number of pages once a day using cron, 2) store it in database, 3) show static generated code from database. But before doing it I've thought to ask here. -- Tadas Talaikis [EMAIL PROTECTED] http://www.xongoo.com - Original Message - From: Robert Cummings [EMAIL PROTECTED] To: Xongoo!com: Central unit [EMAIL PROTECTED] Cc: PHP-General [EMAIL PROTECTED] Sent: Saturday, August 21, 2004 7:32 PM Subject: Re: [PHP] for loops performance On Sat, 2004-08-21 at 12:17, Xongoo!com: Central unit wrote: Holla, Maybe someone knows how to improve for loops performance? When generating 1000's of pages, it oads in 10-20 seconds. Maybe there is some solution I don't know about? Give us an example of your for loop that is having efficiency problems. Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops performance
Xongoo!Com: Central Unit wrote: Here's: for ($c=1; $c$numpages; $c++){ echo a href=page$c.html$c/a | ; } When it generates 1-10, it is normal 0.05 s, but often I need more than 1000, so when generating 100's - it is 0.5-1.5 sec., when more than 1000 - 10+ s. I am thinking on running sopme sort of: 1) generate code of number of pages once a day using cron, 2) store it in database, 3) show static generated code from database. But before doing it I've thought to ask here. -- Tadas Talaikis [EMAIL PROTECTED] http://www.xongoo.com - Original Message - From: Robert Cummings [EMAIL PROTECTED] To: Xongoo!com: Central unit [EMAIL PROTECTED] Cc: PHP-General [EMAIL PROTECTED] Sent: Saturday, August 21, 2004 7:32 PM Subject: Re: [PHP] for loops performance On Sat, 2004-08-21 at 12:17, Xongoo!com: Central unit wrote: Holla, Maybe someone knows how to improve for loops performance? When generating 1000's of pages, it oads in 10-20 seconds. Maybe there is some solution I don't know about? Give us an example of your for loop that is having efficiency problems. Cheers, Rob. You can do this once and instead of echoing the links, save then in a session var and use that on subsequent pages. Maybe on first page or before in some other script: session_start(); for ($c=1; $c$numpages; $c++){ $_SESSION['links'] .= a href=page$c.html$c/a | ; } Then on other pages: session_start(); echo $_SESSION['links']; -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops performance
Xongoo!com: Central unit wrote: Maybe someone knows how to improve for loops performance? When generating 1000's of pages, it oads in 10-20 seconds. Maybe there is some solution I don't know about? If you only generate 100s of pages, it'll probably load about ten times faster... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] arrays, loops, vars and props
Jason Davidson mailto:[EMAIL PROTECTED] on Wednesday, March 10, 2004 12:25 AM said: would the following example be faster or slower had i simply done $this-myArray[$i] = $i; class MyClass { var $myArray = array(); function MyClass() { $myTempArray = array(); for($i=0;$i100;$i++) $myTempArray[$i] = $i; $this-myArray = $myTempArray; } } here's how i would do it (coding styles aside): function MyClass() { $limit = 100; $i = -1; while(++$i $limit) { $this-myArray[] = $i; } } chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] arrays, loops, vars and props
i would do it this way function MyClass() { $this-myArray = range(0, 99); } luis. Chris W. Parker [EMAIL PROTECTED] escribió en el mensaje news:[EMAIL PROTECTED] Jason Davidson mailto:[EMAIL PROTECTED] on Wednesday, March 10, 2004 12:25 AM said: would the following example be faster or slower had i simply done $this-myArray[$i] = $i; class MyClass { var $myArray = array(); function MyClass() { $myTempArray = array(); for($i=0;$i100;$i++) $myTempArray[$i] = $i; $this-myArray = $myTempArray; } } here's how i would do it (coding styles aside): function MyClass() { $limit = 100; $i = -1; while(++$i $limit) { $this-myArray[] = $i; } } chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] arrays, loops, vars and props
here's how i would do it (coding styles aside): function MyClass() { $limit = 100; $i = -1; while(++$i $limit) { $this-myArray[] = $i; } } Don't forget poor old range: $this-myArray = range(0, 99); - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] arrays, loops, vars and props
Luis Mirabal mailto:[EMAIL PROTECTED] on Wednesday, March 10, 2004 12:30 PM said: i would do it this way function MyClass() { $this-myArray = range(0, 99); } guys (luis), guys (mike), let's not try to one-up each other... ... ... but i would take it a step further. :P function MyClass($limit = 100) { $this-myArray = range(0, $limit-1); } c. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] arrays, loops, vars and props
Im fully aware of diffrent ways of doing it, my question is, in the 2 ways i mentioned, which is more efficient. Ill take the question to the internals list. Thanks for your responses. Jason Chris W. Parker [EMAIL PROTECTED] wrote: Luis Mirabal mailto:[EMAIL PROTECTED] on Wednesday, March 10, 2004 12:30 PM said: i would do it this way function MyClass() { $this-myArray = range(0, 99); } guys (luis), guys (mike), let's not try to one-up each other... ... ... but i would take it a step further. :P function MyClass($limit = 100) { $this-myArray = range(0, $limit-1); } c. -- 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] Nested Loops
On 18 February 2004 22:13, Alex Hogan wrote: Sorry..., Line 17 is: print trtda href=\$id\$row2[$rtxt]/a/td/tr; I haven't a clue what this is relating to (bit *too* much snippage there!), but I think that statement is going to need some curly braces to have a chance of working as intended: print trtda href=\$id\{$row2[$rtxt]}/a/td/tr; Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Nested Loops
Thanks for the help guys..., After some sleep and some food this is where it's gone; $query = select wn_pdate, wn_text, wn_id . from whatsnew . order by wn_pdate; $pdate = ; while($row = mssql_fetch_array($result)){ if ($pdate != $row[0]) { print trtd . $row[0]/td/tr; $pdate = $row[0]; } print trtda href=\$id\ . $row[1] . /a/td/tr; } Results; Date 1 Item one Item two Item three Date 2 Item four Item five Item six ... etc It produces the results that I was looking for and it's much less code. alex hogan -Original Message- From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED] Sent: Thursday, February 19, 2004 4:50 AM To: 'Alex Hogan'; PHP General list Subject: RE: [PHP] Nested Loops On 18 February 2004 22:13, Alex Hogan wrote: Sorry..., Line 17 is: print trtda href=\$id\$row2[$rtxt]/a/td/tr; I haven't a clue what this is relating to (bit *too* much snippage there!), but I think that statement is going to need some curly braces to have a chance of working as intended: print trtda href=\$id\{$row2[$rtxt]}/a/td/tr; Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 ** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. **
RE: [PHP] Nested Loops
Alex Hogan mailto:[EMAIL PROTECTED] on Wednesday, February 18, 2004 2:06 PM said: Do I have something wrong with my syntax? Is there an easier way to do this? i don't know the answer to either of those questions but if it's complaining of an undefined index you might want to try print_r() and see what's actually stored within rs[] each pass through the loop. even better would be to look up the mssql functions and see if there is one that can turn your entire result set into an array with both numerical and text indices. then you can print_r() the entire array and see what's going on. hth, chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Nested Loops
Using print_r($var) shows that the vars are returning the right values, and where they're supposed to. Right in between the error messages. Doh. alex ** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. **
RE: [PHP] For Loops and Variables??
John Ryan mailto:[EMAIL PROTECTED] on Saturday, September 13, 2003 9:26 AM said: When I use for loops, at the start of each iteration, the variables hold the values from the last loop. You're doing it wrong then (I think). 1. You should always initialize your loop counters. i.e. $x = 0; while($x 100) { $x++; } 2. Don't use the same counter name in all your loops. This is bad: for($x=0;$x100;$x++) { for($x=0;$x100;$x++) { echo i'm going to go on forever!!; } } This Is Good(tm): for($x=0;$x100;$x++) { for($x=0;$x100;$x++) { echo Me happy now!!; } } Does that help? Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] For Loops and Variables??
Chris W. Parker on Tuesday, September 16, 2003 4:07 PM said: This Is Good(tm): for($x=0;$x100;$x++) { for($x=0;$x100;$x++) { echo Me happy now!!; } } Hehe... whoops! Should be: for($x=0;$x100;$x++) { for($y=0;$y100;$y++) { echo Me happy now!!; } } BYE! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loops and Variables??
* Thus wrote John Ryan ([EMAIL PROTECTED]): When I use for loops, at the start of each iteration, the variables hold the values from the last loop. First, is there an elegant way of clearing variables at the start of each loop rather than using unset???! It just seems wrong. I'm unclear as to what elegant implies. Also, all my problems would be solved if variables in a for loop were kept local, but everything by default is a global. Can I change this in php.ini or something?? no, there are only two scopes in php, it is either GLOBAL or local inside a function/class. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] infinate loops
where is $row['BillPeriod'] set? and what is its value? Chris Knipe wrote: Lo, Quite desperate now... Or at least, I'm starting to get there... Can anyone perhaps see why this loop is not exiting??? $quit=$now; $glet=getdate($row['RenewDate']); // debug echo howlong: . $howlong; while($quit$howlong) { // debug echo quit: . $quit . br; $quit=mktime(0, 0, 0, $glet['mon']+$row['BillPeriod'], $glet['mday'], $glet['year']); $retl+=$row['Cost']; $glet=getdate($quit); } The values, $now = 1036360800 (mktime()) $row['RenewDate'] = 1035928800 (MySQL DB - VARCHAR(12)) $row['Cost'] = xx.xx (MySQL DB - DOUBLE(6,2)) $howlong is defined further up $howlong=mktime(0, 0, 0, $_POST['month'], 1, $_POST['year']) where... 0 $_POST['month'] 12 2001 $_POST['year'] 2005 From the debug (Browser output)... howlong: 1133388000 - now: 1036023598 (RenewDate: 1036360800) quit: 1036023598 quit: 1036360800 quit: 1036360800 quit: 1036360800 Thus, $quit is never incremented I'm *STUMPED* why not, or how to fix this? :(( Each time, PHP times out (Script execution time exceeded), and it *always* gives a line number for the timeout, that is inside the above while loop. Hence, to my understanding, the loop never exits The loop, comes from cbms from voxel.net, stats.php Thanks for the help! -- me -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops
it works for me just the way you have itexcept of course that you are telling it to only print to y because you are saying z Steve At 12:50 PM 5/30/2002 +0800, Jason Wong wrote: On Thursday 30 May 2002 11:46, Peter wrote: Just a query ... has any one else noticed this for($i = a; $i z; $i++) { print $i; echo BR;} will print out a right down to yz It should only print to 'y' ... but replace the letters with numbers eg for($i = 1; $i 10; $i++) { print $i; echo BR;} and it prints 1 thru to 10 ... and should only print to '9' ... and any one know a reason for this? ... so if it does otherwise for you then you've got a bug in your version of php! -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Many people are desperately looking for some wise advice which will recommend that they do what they want to do. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ow3 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loops
On Thursday 30 May 2002 11:46, Peter wrote: Just a query ... has any one else noticed this for($i = a; $i z; $i++) { print $i; echo BR;} will print out a right down to yz It should only print to 'y' ... but replace the letters with numbers eg for($i = 1; $i 10; $i++) { print $i; echo BR;} and it prints 1 thru to 10 ... and should only print to '9' ... and any one know a reason for this? ... so if it does otherwise for you then you've got a bug in your version of php! -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Many people are desperately looking for some wise advice which will recommend that they do what they want to do. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loops [ newbie ]
On Thursday 17 May 2001 13:58, [EMAIL PROTECTED] wrote: i would think that a while loop could do this and possibly write the output, minus the line i want to take away to a temp file and then copy it over. in bash i would use a statement like: while read i; do blah done $filename $filename.tmp however i am not certain how to read in the contents of a file for comparison within a while loop. this is just going to be an uphill thread since my next question will be for the blah portion :) http://php.net/file http://php.net/foreach http://php.net/fopen http://php.net/fwrite Should get you started. -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) ...1000100011010101101010110100111010113... -- 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]
Re: [PHP] while loops [ newbie ]
[EMAIL PROTECTED] wrote: i have a file $file that is full of usernames and descriptions, one per line. i have another variable $username that i would like to compare against each line in the file and remove the line that matches the username field identically. $filename charles routers craig systems tony portmasters i would think that a while loop could do this and possibly write the output, minus the line i want to take away to a temp file and then copy it over. in bash i would use a statement like: while read i; do blah done $filename $filename.tmp however i am not certain how to read in the contents of a file for comparison within a while loop. this is just going to be an uphill thread since my next question will be for the blah portion :) Use fopen() to open the file, while ( ! feof( $fp ) ) to loop through the file until the end of it is reached and fgets() to read one line at a time. Use explode() to grab the first word on each line, compare it to your other variable and write each line to a new variable if it doesn't match. Then use fwrite to write to a temporary file and copy that file over the original. -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ -- 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]
Re: [PHP] nested loops and PHPLIB templates
Hello paula, Monday, April 09, 2001, 6:47:21 AM, you wrote: p I was sending desperate emails to this list related to nested loops and array comparision. p Well, just let you know that the problem seems to be that I'm using this with PHPLIB p templates and those can't handle nested loops. template.html: table !-- BEGIN row -- tr !-- BEGIN column -- td{val}/td !-- END column -- /tr !-- END row -- /table code: // place here some code for multi-row multi-column data array $tpl = new Template; $tpl-set_file('tp', 'template.html'); $tpl-set_block('tp', 'row', 'row_parsed'); $tpl-set_block('row', 'column', 'column_parsed'); foreach ($rows as $row = $columns) { /* IMPORTANT: free the column block from previous results, do it like this: */ $tpl-set_var('column_parsed', ''); foreach ($columns as $column) { $tpl-set_var('val', $column); $tpl-parse('column_parsed', 'column', true); } $tpl-parse('row_parsed', 'row', true); } $tpl-pparse('out', 'tp'); So, you have nested blocks filled with nested loops. -- Best regards, Maxim Derkachev mailto:[EMAIL PROTECTED] Symbol-Plus Publishing Ltd. phone: +7 (812) 324-53-53 http://www.Books.Ru -- All Books of Russia -- 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]
Re: [PHP] nested loops and PHPLIB templates
On Sun, Apr 08, 2001 at 10:47:21PM -0400, paula wrote: I was sending desperate emails to this list related to nested loops and array comparision. Well, just let you know that the problem seems to be that I'm using this with PHPLIB templates and those can't handle nested loops. Please subscribe to the PHPLib mailing list at php.net/support.php. If I would know that a week ago I would avoid nightmares and had 6 pounds more of weight. That depends on your size, I could need some more pounds :) -Egon -- LinuxTag, Stuttgart, Germany: July 5-8 2001: http://www.linuxtag.de/ All known books about PHP and related books: http://php.net/books.php Concert Band of the University of Hohenheim: http://www.concert-band.de/ First and second bestselling book in German: http://www.php-buch.de/ -- 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]