php-general Digest 30 Apr 2010 17:14:11 -0000 Issue 6720
php-general Digest 30 Apr 2010 17:14:11 - Issue 6720 Topics (messages 304765 through 304786): Re: Getting root privs 304765 by: Jim Lucas 304766 by: Nilesh Govindarajan 304779 by: Paul M Foster 304780 by: Ashley Sheridan 304781 by: Nilesh Govindarajan 304782 by: Nilesh Govindarajan 304783 by: Ashley Sheridan Re: Two color rows in table inside while iteration 304767 by: Daevid Vincent 304771 by: Richard Quadling 304772 by: Jay Blanchard 304776 by: Paul M Foster 304777 by: Ashley Sheridan 304778 by: Jay Ess Re: CURL cannot connect to URL - IP address - after successful connection 304768 by: Pete Ford 304769 by: ioannes.btinternet.com Re: In need of CVS/SVN checkout script for Production servers 304770 by: David Otton ldap add Invalid DN syntax 304773 by: Manolis Vlachakis 304774 by: Ashley Sheridan 304775 by: Manolis Vlachakis How to simplify the management of 250+ nodes and 1000+ users , in Drupal 304784 by: ebhakt How to Force IE to download text file? 304785 by: Ali Asghar Toraby Parizy 304786 by: Andre Polykanine Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) -- 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 ---End Message--- ---BeginMessage--- On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! ---End Message--- ---BeginMessage--- On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? If you can find an open source control panel (like webmin), you could download the code and examine it. Paul -- Paul M. Foster ---End Message--- ---BeginMessage--- On Fri, 2010-04-30 at 10:40 -0400, Paul M Foster wrote: On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files
php-general Digest 1 May 2010 05:54:11 -0000 Issue 6721
INTO guns( id,manufacturer, type, model, caliber, condition, price, description, image_file_name,submitted ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber', '$condition', '$price', '$description','$image_file_name', ' ', '$available'); INSERT INTO images (id, image_file) VALUES('','$image_file'); $sqlResult = $batchconnection-multi_query($sqlStatements); if($sqlResult == true) { echo Successfully Inserted Records; } else { echo Some Error Occured While Inserting Records; } } } } } mysqli_close($batchconnection); } ? __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com ---End Message--- ---BeginMessage--- On Fri, 2010-04-30 at 20:43 -0400, Gary wrote: I have this duplicate code on another site and it works fine. The image is uploaded to the images folder, the information is not submitted to the database. I get the error Some Error Occured While Inserting Records This is only on a local machine so I have not yet included and safegaurds like stripslashes or my_real_escape_string. Thanks for your help Gary ?php if (isset($_POST['submit'])) { $manufacturer=($_POST['manufacturer']); $type=($_POST['type']); $model=($_POST['model']); $caliber=($_POST['caliber']); $condition=($_POST['condition']); $price=($_POST['price']); $description=($_POST['description']); $image_file_name=($_POST['image_file_name']); $image_file=($_FILES['image_file']); $available=($_POST['available']); $image_file = $_FILES['image_file']['name']; $image_type = $_FILES['image_file']['type']; $image_size = $_FILES['image_file']['size']; include ('includes/connect_local.inc.php'); if(image_size 300) { class ImgResizer { private $originalFile = 'image_file'; public function __construct($originalFile = 'image_file') { $this - originalFile = $originalFile; } public function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false; } $src = imagecreatefromjpeg($this - originalFile); list($width, $height) = getimagesize($this - originalFile); $newHeight = ($height / $width) * $newWidth; $tmp = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); if (file_exists($targetFile)) { unlink($targetFile); } imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 - 100 for output image quality with 100 being the most luxurious } } } if (!empty($type) !empty($image_file)) { if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') || ($image_type == 'image/pjpeg') || ($image_type == 'image/png') ($image_size 300)) { if ($_FILES['image_file']['error'] == 0) { // Move the file to the target upload folder $target = 'images/' . $image_file; if (move_uploaded_file($_FILES['image_file']['tmp_name'], $target)){ $batchconnection; $sqlStatements = INSERT INTO guns( id,manufacturer, type, model, caliber, condition, price, description, image_file_name,submitted ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber', '$condition', '$price', '$description','$image_file_name', ' ', '$available'); INSERT INTO images (id, image_file) VALUES('','$image_file'); $sqlResult = $batchconnection-multi_query($sqlStatements); if($sqlResult == true) { echo Successfully Inserted Records; } else { echo Some Error Occured While Inserting Records; } } } } } mysqli_close($batchconnection); } ? __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com Is it possible that this server doesn't like batch queries? Try splitting them out into individual queries and seeing if that helps. If that doesn't do the trick, print out the SQL query string to see if it's what you expect. It might be working fine on the other server, but I've seen enough strange things happen before to know that sometimes 'poo' happens. Thanks, Ash http://www.ashleysheridan.co.uk ---End Message--- ---BeginMessage--- This is the other code that works on the same server. ?php if (isset($_POST['submit'])) { $caption=($_POST['caption']); $description=($_POST['description']); $image_file=($_FILES['image_file']); $where_taken=($_POST['where_taken']); $fox=($_POST['fox']); $wolves=($_POST['wolves']); $wildlife=($_POST['wildlife']); $scenic=($_POST['scenic']); $birds=($_POST['birds']); $eagles=($_POST['eagles']); $deer=($_POST['deer']); $small_mammals=($_POST['small_mammals']); $large_mammals=($_POST['large_mammals']); $dogs=($_POST['dogs']); $cats=($_POST['cats']); $flowers=($_POST['flowers
Re: [PHP] Getting root privs
On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Two color rows in table inside while iteration
-Original Message- while(foo){ $tr = (0 == $trColor % 2)? #E8E8E8 : #FF; echo tr style=\background-color:.$tr.\; ... Don't do this modulus (%) math Just toggle a boolean!! tr class=?= ($r = !$r) ? dataRow1 : dataRow2; ? smime.p7s Description: S/MIME cryptographic signature
RE: [PHP] Two color rows in table inside while iteration
On Fri, 2010-04-30 at 06:14 -0500, Jay Blanchard wrote: [snip] Don't do this modulus (%) math Just toggle a boolean!! tr class=?= ($r = !$r) ? dataRow1 : dataRow2; ? [/snip] What is wrong with modulus math Modulus is the most elegant solution I reckon. Imagine if you only needed to highlight every 3rd row, or 4th? Easy to change the modulus for it, not so easy to re-work a binary switch. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Two color rows in table inside while iteration
Paul M Foster wrote: +1 This thread came up before, and tedd's solution was the least complex, as far as I could tell. I shamelessly stole his code and regularly use it in my own projects. ;-} Or if one choose to use Smarty template. tr bgcolor={cycle values=#ee,#d0d0d0} http://www.smarty.net/manual/en/language.function.cycle.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting root privs
On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? If you can find an open source control panel (like webmin), you could download the code and examine it. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting root privs
On Fri, 2010-04-30 at 10:40 -0400, Paul M Foster wrote: On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? If you can find an open source control panel (like webmin), you could download the code and examine it. Paul -- Paul M. Foster You could use exce() to run a sudo command (piping the password through to it or add the apache user into the sudoers list) to run things at the root level. You must be very very careful with this though, and only use it as a last resort if you absolutely have to, as any sort of vulnerability in your script could compromise your entire server. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Getting root privs
On 04/30/2010 08:10 PM, Paul M Foster wrote: On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? If you can find an open source control panel (like webmin), you could download the code and examine it. Paul Webmin is written in perl. I will see the code of web-cp which is php based. -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting root privs
On 04/30/2010 08:12 PM, Ashley Sheridan wrote: On Fri, 2010-04-30 at 10:40 -0400, Paul M Foster wrote: On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? If you can find an open source control panel (like webmin), you could download the code and examine it. Paul -- Paul M. Foster You could use exce() to run a sudo command (piping the password through to it or add the apache user into the sudoers list) to run things at the root level. You must be very very careful with this though, and only use it as a last resort if you absolutely have to, as any sort of vulnerability in your script could compromise your entire server. Thanks, Ash http://www.ashleysheridan.co.uk That was what my basic idea about implementing it, but just put up a discussion here to see if there is really any other method except sudo- and there is that cron one as suggested by Jim Lucas. -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting root privs
On Fri, 2010-04-30 at 20:23 +0530, Nilesh Govindarajan wrote: On 04/30/2010 08:12 PM, Ashley Sheridan wrote: On Fri, 2010-04-30 at 10:40 -0400, Paul M Foster wrote: On Fri, Apr 30, 2010 at 12:11:17PM +0530, Nilesh Govindarajan wrote: On 04/30/2010 11:26 AM, Jim Lucas wrote: Nilesh Govindarajan wrote: Hi, As you know there are lot of control panels lying around like Cpanel, Lxadmin, most of them based on PHP. The control panels allow editing of system files which requires root privileges, can somebody tell me how to gain root privileges inside the script so that it can be useful if I want to give my users a DNS editing interface instead of loading a big bloated control panel. We use an interface that writes everything to a DB. Then, every 5 minutes, a cron job comes around and dumps the db and builds the zone files for us. Might try something similar. It would be a lot safer then giving root access via PHP... :) Hmm that's a great idea. But my question is in general, suppose I get some freelance job to write a control panel for managing httpd, etc. Same procedure can be used ? I think so ? If you can find an open source control panel (like webmin), you could download the code and examine it. Paul -- Paul M. Foster You could use exce() to run a sudo command (piping the password through to it or add the apache user into the sudoers list) to run things at the root level. You must be very very careful with this though, and only use it as a last resort if you absolutely have to, as any sort of vulnerability in your script could compromise your entire server. Thanks, Ash http://www.ashleysheridan.co.uk That was what my basic idea about implementing it, but just put up a discussion here to see if there is really any other method except sudo- and there is that cron one as suggested by Jim Lucas. -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! To make things a little bit more secure when using exec() you could call a series of custom Bash scripts which you can have set up to only accept certain ranges of parameters, which would avoid someone passing a string like nasty_command here to the command line. Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] How to simplify the management of 250+ nodes and 1000+ users , in Drupal
Hi, I have written this tool : Portal Manager :: Drupal Management Assembly which is to remotely manage a drupal based website You can manage and edit user properties You can manage and edit posts you can sort posts on the bases of taxonomies and then manage and edit posts The tool is written in C# WPF and needs .net framework 3.5 to be pre-installed Please find the software here: LINK http://ebhakt.com/content/portal-manager-drupal- management-assembly Please give your valuable feedback, its highly welcome... NOTE: For working of this software you need to download and install services module and configure it to give permissions to anonymous users -- Bhaskar Tiwari GTSE Generalist Directory Services Microsoft All we have to decide is what to do with the time that has been given to us http://www.ebhakt.com/ http://fytclub.net/ http://ebhakt.info/
[PHP] How to Force IE to download text file?
I have written this code to export data to a text file and asks user to save generated file. It works with Firefox perfectly, but IE shows content of file instead of prompting the download window. How can I force IE to show the download dialog? ?php Header(Content-disposition: attachement; filename=data.txt); Header(Content-type: text/plain); echo $some_data; ? -- Ali Asghar Torabi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to Force IE to download text file?
Hello Ali, It's attachment, not attachement. Maybe here's the reason? Just a thought. -- With best regards from Ukraine, Andre Skype: Francophile; WlmMSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: m_elensule - Original message - From: Ali Asghar Toraby Parizy aliasghar.tor...@gmail.com To: php-general@lists.php.net php-general@lists.php.net Date: Friday, April 30, 2010, 7:19:38 PM Subject: [PHP] How to Force IE to download text file? I have written this code to export data to a text file and asks user to save generated file. It works with Firefox perfectly, but IE shows content of file instead of prompting the download window. How can I force IE to show the download dialog? ?php Header(Content-disposition: attachement; filename=data.txt); Header(Content-type: text/plain); echo $some_data; ? -- Ali Asghar Torabi -- 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] How to Force IE to download text file?
On Fri, Apr 30, 2010 at 9:19 AM, Ali Asghar Toraby Parizy aliasghar.tor...@gmail.com wrote: I have written this code to export data to a text file and asks user to save generated file. It works with Firefox perfectly, but IE shows content of file instead of prompting the download window. How can I force IE to show the download dialog? ?php Header(Content-disposition: attachement; filename=data.txt); Header(Content-type: text/plain); echo $some_data; ? We usually do something like this. Although I am not sure about text files. header(Content-Disposition: attachment; filename=\.urldecode(basename($file)).\;); header(Content-Type: application/force-download); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two color rows in table inside while iteration
At 10:34 AM -0400 4/30/10, Paul M Foster wrote: On Thu, Apr 29, 2010 at 05:34:38PM -0400, tedd wrote: Please critically review my example. +1 This thread came up before, and tedd's solution was the least complex, as far as I could tell. I shamelessly stole his code and regularly use it in my own projects. ;-} Paul Paul: Thanks for the plug. All the code I provide on this list and on my various web sites is for free for anyone, except for governments (i.e., local, state, federal, other), to use, review, and/or comment as they wish without any obligation to me. Oh, as for governments if you want a copy of anything please contact me directly, I have a few forms for you to fill out. The point of sharing is to improve product -- agile works. My livelihood is not compromised because someone is using a small snip-it of mine. Hopefully my real code (the stuff I sell to clients) is more involved and has more value than that. 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] Two color rows in table inside while iteration
At 4:37 PM +0200 4/30/10, Jay Ess wrote: Paul M Foster wrote: +1 This thread came up before, and tedd's solution was the least complex, as far as I could tell. I shamelessly stole his code and regularly use it in my own projects. ;-} Or if one choose to use Smarty template. tr bgcolor={cycle values=#ee,#d0d0d0} http://www.smarty.net/manual/en/language.function.cycle.php Yeah, like that keeps presentation separate from data while making things simpler, right? I don't think so. Embedding styling attributes in html is simply not following best practices. For example, if you have 100 pages of the above embedded code and the client says Hey, let's change the color of that table -- then you are going to have to change 100 pages of code whereas if you followed best practices then you would change only one rule in css. 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] Two color rows in table inside while iteration
On Fri, 2010-04-30 at 13:59 -0400, tedd wrote: At 4:37 PM +0200 4/30/10, Jay Ess wrote: Paul M Foster wrote: +1 This thread came up before, and tedd's solution was the least complex, as far as I could tell. I shamelessly stole his code and regularly use it in my own projects. ;-} Or if one choose to use Smarty template. tr bgcolor={cycle values=#ee,#d0d0d0} http://www.smarty.net/manual/en/language.function.cycle.php Yeah, like that keeps presentation separate from data while making things simpler, right? I don't think so. Embedding styling attributes in html is simply not following best practices. For example, if you have 100 pages of the above embedded code and the client says Hey, let's change the color of that table -- then you are going to have to change 100 pages of code whereas if you followed best practices then you would change only one rule in css. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com I agree. Inline styles are useful in a few fringe cases, but if you can avoid them then it's best practice to do so. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Two color rows in table inside while iteration
At 7:26 PM +0100 4/30/10, Ashley Sheridan wrote: On Fri, 2010-04-30 at 13:59 -0400, tedd wrote: At 4:37 PM +0200 4/30/10, Jay Ess wrote: Paul M Foster wrote: +1 This thread came up before, and tedd's solution was the least complex, as far as I could tell. I shamelessly stole his code and regularly use it in my own projects. ;-} Or if one choose to use Smarty template. tr bgcolor={cycle values=#ee,#d0d0d0} http://www.smarty.net/manual/en/language.function.cycle.phphttp://www.smarty.net/manual/en/language.function.cycle.php Yeah, like that keeps presentation separate from data while making things simpler, right? I don't think so. Embedding styling attributes in html is simply not following best practices. For example, if you have 100 pages of the above embedded code and the client says Hey, let's change the color of that table -- then you are going to have to change 100 pages of code whereas if you followed best practices then you would change only one rule in css. Cheers, tedd I agree. Inline styles are useful in a few fringe cases, but if you can avoid them then it's best practice to do so. Thanks, Ash http://www.ashleysheridan.co.ukhttp://www.ashleysheridan.co.uk Ash: The only fringe cases I can think of are those that could be solved by using a span tag. Do you have any examples otherwise? 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] Two color rows in table inside while iteration -- just say no to mod
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Modulus is the most elegant solution I reckon. Imagine if you only needed to highlight every 3rd row, or 4th? Easy to change the modulus for it, not so easy to re-work a binary switch. -Original Message- From: Richard Quadling [mailto:rquadl...@googlemail.com] The modulus is a good option when there are more than 2 states. Say a 5 row fade ... $a=0; while ($row=mysql_fetch_...){ echo tr class=??\alternate-row-.(1 + (++$a%5)).\... } giving alternate-row-1, alternate-row-2, alternate-row-3, alternate-row-4 and alternate-row-5 Okay, how many tables do you EVER see with more than TWO colors? Come on now. Show me some URL's to REAL sites (not some contrived examples) that use multiple row colors or fades in a rotating fashion. Not talking about a highlight roll-over, nor am I talking about highlighting rows of certain criteria in different colors, as both of those are not the problem for this solution. I'm talking about a straight up table that cycles each row more than 2 colors. 99% of your tables are 2 colors, and flipping a bit (i.e. Boolean) is WAY faster to compute than modulus and also easier to understand. http://www.youtube.com/watch?v=pXhKzY0BKwY ;-) (I say that out of love!) d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two color rows in table inside while iteration
On Fri, 2010-04-30 at 15:59 -0400, tedd wrote: At 7:26 PM +0100 4/30/10, Ashley Sheridan wrote: On Fri, 2010-04-30 at 13:59 -0400, tedd wrote: At 4:37 PM +0200 4/30/10, Jay Ess wrote: Paul M Foster wrote: +1 This thread came up before, and tedd's solution was the least complex, as far as I could tell. I shamelessly stole his code and regularly use it in my own projects. ;-} Or if one choose to use Smarty template. tr bgcolor={cycle values=#ee,#d0d0d0} http://www.smarty.net/manual/en/language.function.cycle.phphttp://www.smarty.net/manual/en/language.function.cycle.php Yeah, like that keeps presentation separate from data while making things simpler, right? I don't think so. Embedding styling attributes in html is simply not following best practices. For example, if you have 100 pages of the above embedded code and the client says Hey, let's change the color of that table -- then you are going to have to change 100 pages of code whereas if you followed best practices then you would change only one rule in css. Cheers, tedd I agree. Inline styles are useful in a few fringe cases, but if you can avoid them then it's best practice to do so. Thanks, Ash http://www.ashleysheridan.co.ukhttp://www.ashleysheridan.co.uk Ash: The only fringe cases I can think of are those that could be solved by using a span tag. Do you have any examples otherwise? Cheers, tedd I can't think of any right now, but I know that on occassion I've used inline styles where I know that the style will never be repeated and was a one-off style to just perform a quick fix. I know it's a messy thing to do, but I'm sure there must be a good reason for them somewhere! Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] multi dimensional array question
hello everybody here is my array(s) $us_census = array('NY' = array('New York' = 8008278), 'CA' = array('Los Angeles' = 3694820, 'San Diego' = 1223400), 'IL' = array('Chicago' = 2896016), 'TX' = array('Houston' = 1953631, 'Dallas' = 1188580, 'San Antonio' = 1144646), 'PA' = array('Philadelphia' = 1517550), 'AZ' = array('Phoenix' = 1321045), 'MI' = array('Detroit' = 951270)); print tabletrthState/ththCity/ththPopulation/ththTotal/th/tr; // $state is the key and $states is the value foreach ($us_census as $state = $cities) { // $state is the key and $habitant is the value foreach ($cities as $city = $habitants){ print trtd$state/tdtd$city/tdtd$habitants/tdtd/td/tr; } } Now i also want to be able to count the total population per state, i am stucked... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two color rows in table inside while iteration -- just say no to mod
On Apr 30, 2010, at 4:20 PM, Daevid Vincent wrote: -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Modulus is the most elegant solution I reckon. Imagine if you only needed to highlight every 3rd row, or 4th? Easy to change the modulus for it, not so easy to re-work a binary switch. -Original Message- From: Richard Quadling [mailto:rquadl...@googlemail.com] The modulus is a good option when there are more than 2 states. Say a 5 row fade ... $a=0; while ($row=mysql_fetch_...){ echo tr class=??\alternate-row-.(1 + (++$a%5)).\... } giving alternate-row-1, alternate-row-2, alternate-row-3, alternate-row-4 and alternate-row-5 Okay, how many tables do you EVER see with more than TWO colors? Come on now. Show me some URL's to REAL sites (not some contrived examples) that use multiple row colors or fades in a rotating fashion. Not talking about a highlight roll-over, nor am I talking about highlighting rows of certain criteria in different colors, as both of those are not the problem for this solution. I'm talking about a straight up table that cycles each row more than 2 colors. 99% of your tables are 2 colors, and flipping a bit (i.e. Boolean) is WAY faster to compute than modulus and also easier to understand. http://www.youtube.com/watch?v=pXhKzY0BKwY ;-) (I say that out of love!) A bit of a contrived example... BUT... I could envision having multiple (more then 2) colors on a blog with comments... Maybe it's a patriotic blog and they want the comments to cycle between red, white blue... (Or your countries colors) And yes I know that you could assume white is a default... But I know some people who have the default color of their web browser set to bright pink to point out where rules aren't specifically assigned :) And unless we are adding a multiple seconds to the load time is anyone going to notice a difference of 1 second? Or am I wrong? Also... I'm not trying to start a fight... Just trying to understand the different possibilities and the impact :) Hoping to write the next facebook eventually But aren't we all? ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] multi dimensional array question
Am 01.05.2010 00:57, schrieb Nick Balestra: hello everybody here is my array(s) $us_census = array('NY' = array('New York' = 8008278), 'CA' = array('Los Angeles' = 3694820, 'San Diego' = 1223400), 'IL' = array('Chicago' = 2896016), 'TX' = array('Houston' = 1953631, 'Dallas' = 1188580, 'San Antonio' = 1144646), 'PA' = array('Philadelphia' = 1517550), 'AZ' = array('Phoenix' = 1321045), 'MI' = array('Detroit' = 951270)); print tabletrthState/ththCity/ththPopulation/ththTotal/th/tr; // $state is the key and $states is the value foreach ($us_census as $state = $cities) { // $state is the key and $habitant is the value foreach ($cities as $city = $habitants){ print trtd$state/tdtd$city/tdtd$habitants/tdtd/td/tr; } } Now i also want to be able to count the total population per state, i am stucked... array_sum() should do it :) foreach ($us_census as $state = $cities) { $population_per_state = array_sum($cities); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] multi dimensional array question
thanks Piero! i was trying to solve an excercise on learning php5 (O'reilyl) book. I am happy abotut his solution with the array_sum funtion you suggested, and my multidimensional array make much more sense to mee then they suggested solution that also much more line of code comapred... look: my solution (with Piero suggeston): and ont he bottom the book solution. what do u say is the best one? why? i am learning so i am interested in understanding why a solution can be better then an other... $us_census = array('NY' = array('New York' = 8008278), 'CA' = array('Los Angeles' = 3694820, 'San Diego' = 1223400), 'IL' = array('Chicago' = 2896016), 'TX' = array('Houston' = 1953631, 'Dallas' = 1188580, 'San Antonio' = 1144646), 'PA' = array('Philadelphia' = 1517550), 'AZ' = array('Phoenix' = 1321045), 'MI' = array('Detroit' = 951270)); print tabletrthState/ththCity/ththPopulation/ththTotal/th/tr; foreach ($us_census as $state = $cities) { foreach ($cities as $city = $habitants){ $tothabitants += $habitants; print trtd$state/tdtd$city/tdtd$habitants/tdtd/td/tr; } } print trtd/tdtd/tdtd/tdtd$tothabitants/td/tr/table; foreach ($us_census as $state = $cities) { $population_per_state = array_sum($cities); print $state $population_per_statebr; } -- the book solution: $population = array('New York' = array('state' = 'NY', 'pop' = 8008278), 'Los Angeles' = array('state' = 'CA', 'pop' = 3694820), 'Chicago' = array('state' = 'IL', 'pop' = 2896016), 'Houston' = array('state' = 'TX', 'pop' = 1953631), 'Philadelphia' = array('state' = 'PA', 'pop' = 1517550), 'Phoenix' = array('state' = 'AZ', 'pop' = 1321045), 'San Diego' = array('state' = 'CA', 'pop' = 1223400), 'Dallas' = array('state' = 'TX', 'pop' = 1188580), 'San Antonio' = array('state' = 'TX', 'pop' = 1144646), 'Detroit' = array('state' = 'MI', 'pop' = 951270)); $state_totals = array( ); $total_population = 0; print tabletrthCity/ththPopulation/th/tr\n; foreach ($population as $city = $info) { $total_population += $info['pop']; $state_totals[$info['state']] += $info['pop']; print trtd$city, {$info['state']}/tdtd{$info['pop']}/td/tr\n; } foreach ($state_totals as $state = $pop) { print trtd$state/tdtd$pop/td\n; } print trtdTotal/tdtd$total_population/td/tr\n; print /table\n;
[PHP] Any One See where this is going wrong?
I have this duplicate code on another site and it works fine. The image is uploaded to the images folder, the information is not submitted to the database. I get the error Some Error Occured While Inserting Records This is only on a local machine so I have not yet included and safegaurds like stripslashes or my_real_escape_string. Thanks for your help Gary ?php if (isset($_POST['submit'])) { $manufacturer=($_POST['manufacturer']); $type=($_POST['type']); $model=($_POST['model']); $caliber=($_POST['caliber']); $condition=($_POST['condition']); $price=($_POST['price']); $description=($_POST['description']); $image_file_name=($_POST['image_file_name']); $image_file=($_FILES['image_file']); $available=($_POST['available']); $image_file = $_FILES['image_file']['name']; $image_type = $_FILES['image_file']['type']; $image_size = $_FILES['image_file']['size']; include ('includes/connect_local.inc.php'); if(image_size 300) { class ImgResizer { private $originalFile = 'image_file'; public function __construct($originalFile = 'image_file') { $this - originalFile = $originalFile; } public function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false; } $src = imagecreatefromjpeg($this - originalFile); list($width, $height) = getimagesize($this - originalFile); $newHeight = ($height / $width) * $newWidth; $tmp = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); if (file_exists($targetFile)) { unlink($targetFile); } imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 - 100 for output image quality with 100 being the most luxurious } } } if (!empty($type) !empty($image_file)) { if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') || ($image_type == 'image/pjpeg') || ($image_type == 'image/png') ($image_size 300)) { if ($_FILES['image_file']['error'] == 0) { // Move the file to the target upload folder $target = 'images/' . $image_file; if (move_uploaded_file($_FILES['image_file']['tmp_name'], $target)){ $batchconnection; $sqlStatements = INSERT INTO guns( id,manufacturer, type, model, caliber, condition, price, description, image_file_name,submitted ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber', '$condition', '$price', '$description','$image_file_name', ' ', '$available'); INSERT INTO images (id, image_file) VALUES('','$image_file'); $sqlResult = $batchconnection-multi_query($sqlStatements); if($sqlResult == true) { echo Successfully Inserted Records; } else { echo Some Error Occured While Inserting Records; } } } } } mysqli_close($batchconnection); } ? __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Any One See where this is going wrong?
On Fri, 2010-04-30 at 20:43 -0400, Gary wrote: I have this duplicate code on another site and it works fine. The image is uploaded to the images folder, the information is not submitted to the database. I get the error Some Error Occured While Inserting Records This is only on a local machine so I have not yet included and safegaurds like stripslashes or my_real_escape_string. Thanks for your help Gary ?php if (isset($_POST['submit'])) { $manufacturer=($_POST['manufacturer']); $type=($_POST['type']); $model=($_POST['model']); $caliber=($_POST['caliber']); $condition=($_POST['condition']); $price=($_POST['price']); $description=($_POST['description']); $image_file_name=($_POST['image_file_name']); $image_file=($_FILES['image_file']); $available=($_POST['available']); $image_file = $_FILES['image_file']['name']; $image_type = $_FILES['image_file']['type']; $image_size = $_FILES['image_file']['size']; include ('includes/connect_local.inc.php'); if(image_size 300) { class ImgResizer { private $originalFile = 'image_file'; public function __construct($originalFile = 'image_file') { $this - originalFile = $originalFile; } public function resize($newWidth, $targetFile) { if (empty($newWidth) || empty($targetFile)) { return false; } $src = imagecreatefromjpeg($this - originalFile); list($width, $height) = getimagesize($this - originalFile); $newHeight = ($height / $width) * $newWidth; $tmp = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); if (file_exists($targetFile)) { unlink($targetFile); } imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 - 100 for output image quality with 100 being the most luxurious } } } if (!empty($type) !empty($image_file)) { if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') || ($image_type == 'image/pjpeg') || ($image_type == 'image/png') ($image_size 300)) { if ($_FILES['image_file']['error'] == 0) { // Move the file to the target upload folder $target = 'images/' . $image_file; if (move_uploaded_file($_FILES['image_file']['tmp_name'], $target)){ $batchconnection; $sqlStatements = INSERT INTO guns( id,manufacturer, type, model, caliber, condition, price, description, image_file_name,submitted ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber', '$condition', '$price', '$description','$image_file_name', ' ', '$available'); INSERT INTO images (id, image_file) VALUES('','$image_file'); $sqlResult = $batchconnection-multi_query($sqlStatements); if($sqlResult == true) { echo Successfully Inserted Records; } else { echo Some Error Occured While Inserting Records; } } } } } mysqli_close($batchconnection); } ? __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com Is it possible that this server doesn't like batch queries? Try splitting them out into individual queries and seeing if that helps. If that doesn't do the trick, print out the SQL query string to see if it's what you expect. It might be working fine on the other server, but I've seen enough strange things happen before to know that sometimes 'poo' happens. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Any One See where this is going wrong?
/png') ($image_size 300)) { if ($_FILES['image_file']['error'] == 0) { // Move the file to the target upload folder $target = 'images/' . $image_file; if (move_uploaded_file($_FILES['image_file']['tmp_name'], $target)){ $batchconnection; $sqlStatements = INSERT INTO guns( id,manufacturer, type, model, caliber, condition, price, description, image_file_name,submitted ,available) VALUES ('','$manufacturer', '$type', '$model', '$caliber', '$condition', '$price', '$description','$image_file_name', ' ', '$available'); INSERT INTO images (id, image_file) VALUES('','$image_file'); $sqlResult = $batchconnection-multi_query($sqlStatements); if($sqlResult == true) { echo Successfully Inserted Records; } else { echo Some Error Occured While Inserting Records; } } } } } mysqli_close($batchconnection); } ? __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com Is it possible that this server doesn't like batch queries? Try splitting them out into individual queries and seeing if that helps. If that doesn't do the trick, print out the SQL query string to see if it's what you expect. It might be working fine on the other server, but I've seen enough strange things happen before to know that sometimes 'poo' happens. Thanks, Ash http://www.ashleysheridan.co.uk __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com __ Information from ESET Smart Security, version of virus signature database 5076 (20100430) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Any One See where this is going wrong?
may be it is not the error with the code. The problem may be with some ' in the input. Print out the mysql error and/or the sql query to see what is going wrong. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php