[PHP] compare lists
I would like to compare strings. I'm using this for my navigation PSEUDO-CODE IF $title CONTAINS "abc: def" print TITLE; print SUB1; print SUB2; print SUB3; ELSE print TITLE; Comparing the number of characters in one string with another does not do the trick. (strcmp) Is there anything besides a general regex? Or is my concern about processing speed unwaranted? There would be dozens of look-ups per page, even using switch-case. -- gil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] compare lists
thx Jason I had overlooked a few functions. My bad. strpos() also works. thx, -- gil > -Original Message- > From: Jason Sheets [mailto:[EMAIL PROTECTED] > Sent: Sunday, January 18, 2004 1:15 PM > To: mayo > Subject: Re: [PHP] compare lists > > > mayo wrote: > > >I would like to compare strings. I'm using this for my navigation > > > >PSEUDO-CODE > > > >IF $title CONTAINS "abc: def" > > > >print TITLE; > > > >print SUB1; > >print SUB2; > >print SUB3; > > > >ELSE > > > >print TITLE; > > > > > >Comparing the number of characters in one string with another > does not do > >the trick. (strcmp) > > > >Is there anything besides a general regex? > > > >Or is my concern about processing speed unwaranted? There would > be dozens of > >look-ups per page, even using switch-case. > > > >-- gil > > > > > > > Look at strstr > > Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] compare lists
thx Richard, wouldn't you know it, you can look for something, can't find it, post a question, and then find it? go figure :-) thx -- gil > -Original Message- > From: Richard Davey [mailto:[EMAIL PROTECTED] > Sent: Sunday, January 18, 2004 1:26 PM > To: mayo > Cc: php-general > Subject: Re: [PHP] compare lists > > > Hello mayo, > > Sunday, January 18, 2004, 6:06:41 PM, you wrote: > > m> I would like to compare strings. I'm using this for my navigation > > m> IF $title CONTAINS "abc: def" > > m> Comparing the number of characters in one string with another > does not do > m> the trick. (strcmp) > > If I have understood your pseudo code correctly then you're not really > comparing strings, you're just checking to see if a string contains a > set of characters (i.e. another string). > > There is no reason why you couldn't do: > > if (strpos($title, "abc: def") === false) > { >// not found > } > else > { > // do stuff > } > > -- > Best regards, > Richardmailto:[EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] inserting info from a query string into sql
PROBLEM I'm trying to insert information from a query string into sql. I have a table with content. The column headers have up and down arrows allowing the user to sort and order by that column. PHP I have default settings set for the variables. If I change the default values the SQL results changes. (good) I can get the query string variables outside the sql. However I can't seem to insert the query string variables into the sql. What am I missing here? thx, Gil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] query strings, global variables
I'm a cold fusion refugee and am having incredible problems with something that I think is relatively easy -- so I must be missing something basic. I would like to pull info from a query string and use it inside a database call I have a navigation bar that includes data pulled from a database. Simplified version below INTO ABOUT CLASSES --section1 --section2 --section3 --section4 I would like to do: //PSEUDO CODE if (section == $sectionName){ display as bold }else{ display normally } PHP SQL call below work nicely: while ($row = mysql_fetch_array($selection)){ echo $row["sectionName"]; } now I would like to do the if/else while ($row = mysql_fetch_array($selection)){ if (section == $sectionName){ echo "" . $row["sectionName"] . ""; }else{ echo $row["sectionName"]; } thx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Shopping Cart, security concerns
I'm making my first shopping cart in PHP. I'm concerned about the security of my session variables, concerned about people altering data (lowering the price). Is there anything I should pay attention to. I've worked extensively with CF, this is my first foray into PHP. Thanks
RE: [PHP] Shopping Cart, security concerns
I have to say it's a pretty simple project. The don't want to keep any information in a db. (!!??!!) Info will be sent to a merchant services account and to the distributor which will process the form. Info will be kept in hidden fields and in session variables then sent off. They have three products (it may rise to 5) and everything will be hardcoded as there are no size or color variations. I told them that it's not advisable to have everything hardcoded but the client insists there is no reason to pull anything from a database. The on-site graphics/web designer person will make the changes. He is competent to do that and did a good job with the basic design. This is not my very first foray into PHP but first time doing something more complicated than 1. if person has this permission then show A else show B or 2. if person is on page 1 then show page 1 as bold else show page 1 as normal Thanks -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Saturday, May 14, 2005 1:54 AM To: mayo Cc: php Subject: Re: [PHP] Shopping Cart, security concerns On Fri, May 13, 2005 8:26 pm, mayo said: > I'm making my first shopping cart in PHP. I'm concerned about the > security of my session variables, concerned about people altering data > (lowering the price). Is there anything I should pay attention to. There are approximately 247 other PHP shopping carts out there. Maybe you'd be better off just installing one of them. Certainly, you should read the source code to several. Your session variables are at-risk on a shared server, usually; And not so much on a dedicated server. Or, more properly, on a dedicated server, if your session data isn't safe, you've got MUCH bigger problems than just your session data. As far as changing the price goes, just don't take the price as an INPUT from your cart/form. The only variables you need to accept from the user in the shopping cart itself are: $product_id and $quantity. For the fulfillment, maybe some location data like $country, $region, $postal to calculate shipping, and then their credit card info. Honestly, setting up a script to accept people's credit card numbers as your very first PHP project is probably not a particularly Good Idea... You can't absorb all the ins and outs of security overnight... Just my opinion. Perhaps you would be better served to install a pre-existing PHP shopping cart, and focus on making it secure and safe, rather than trying to write your own from scratch as well. -- Like Music? http://l-i-e.com/artists.htm -- 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] Shopping Cart, security concerns
No, I would not have prices in the hidden fields. :-) Thanks though for the concern. I do have a few questions about easiest / best way to write this. Especially as I don't have PHP experience, meaning it takes me longer to write the code and more importantly I might miss something important. == Shopping Cart display Item Qty (allow user to change or delete) Item ID (added to session variable by hidden field) Item Name (added to session variable by hidden field) Item Desc Short (added to session variable by hidden field) Item Price (hardcoded. I hate this but it would be pulled from a file or hardcoded - an if else clause. If itemID = 1 then price = x) Page 1 (Shipping Info: Name, Address...) Info forwarded to page two in hidden fields) Page 2 (Billing Address: Name, Address ...) Info forwarded to page three in hidden fields Page 3 - confirmation page Page 4 (CC info) Page 5 (Hidden from consumer Security Check Page) Qty * Price = Qty Tax recalculated Shipping recalculated Relevant data sent to merchant and distributor company Thanks -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Saturday, May 14, 2005 10:52 PM To: mayo Cc: 'php' Subject: RE: [PHP] Shopping Cart, security concerns On Sat, May 14, 2005 6:30 am, mayo said: > I have to say it's a pretty simple project. The don't want to keep any > information in a db. (!!??!!) Info will be sent to a merchant services > account and to the distributor which will process the form. > > Info will be kept in hidden fields and in > session variables then sent off. Don't put anything you *NEED* to be correct/accurate in type="hidden" The web surfer can *CHANGE* that in about 5 seconds and send whatever they want. All your prices, all you shipping costs, all the weights, etc had better be in your PHP source code, as arrays, I guess... You'd really be better off just using a database with an existing cart. The amount of code you'll have to write to do this correctly is insane. > They have three products (it may rise to 5) and everything will be > hardcoded as there are no size or color variations. I told them that > it's not advisable to have everything hardcoded but the client insists > there is no reason to pull anything from a database. The on-site > graphics/web designer person will make the changes. He is competent to > do that and did a good job with the basic design. But you CANNOT put your prices in type="hidden" fields!!! That's EXACTLY how you get a shopping cart where the user changes the price! > This is not my very first foray into PHP but first time doing something > more complicated than > > 1. if person has this permission then show A else show B > > or > > 2. if person is on page 1 then show page 1 as bold else show page 1 as > normal -- Like Music? http://l-i-e.com/artists.htm -- 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] Add to array problem
I'm having a little problem adding to an array. Each time I add to an array it wipes what was previously added. I'm using array_push(). $items=array(); $items=array_push($items, $_POST["whatever"]); I'm missing something easy. thx
[PHP] array, trouble updating
I usually work with cold fusion and took on a little project to get my feet wet in php and am spinning my wheels. What I thought might be difficult was easy and what I thought would be a piece of cake has caused me much grief over the last few days. I'm making a little shopping basket, writing the results to a file, ftping the file to a distributor and sending the CC data to merchant services company. Write to file - easy FTP file to distributor - easy Updating the array in the shopping basket -- not so easy !!??!! A shopping basket should be able to add and delete items (done) You should be able to delete the whole basket (done) Now I need to be able to update quantity - I've spent at least 5 or 6 hours on this and have gotten nowhere!!! This learning exercise is getting to be a major time drag. Any hints would be good. The code is below: -1) { array_splice ($ses_basket_name, $ses_basket_items, 1); array_splice ($ses_basket_amount, $ses_basket_items, 1); array_splice ($ses_basket_price, $ses_basket_items, 1); array_splice ($ses_basket_id, $ses_basket_items, 1); $ses_basket_items--; } } if ($action2 == "deleteItem") { array_splice ($ses_basket_name, $position, 1); array_splice ($ses_basket_amount, $position, 1); array_splice ($ses_basket_price, $position, 1); array_splice ($ses_basket_id, $position, 1); $ses_basket_items--; } ?> 0){ foreach ($_SESSION['ses_basket_name'] as $basket_item){ if ($basket_item==$_GET['basket']){ $double=1; $subtract=1; $basket_position=$basket_position_counter; } $basket_position_counter++; } } if ($double==1){ $oldamount=$_SESSION['ses_basket_amount'][$basket_position]; $_SESSION['ses_basket_amount'][$basket_position]++; $amount=$_SESSION['ses_basket_amount'][$basket_position]; $oldprice=$_SESSION['ses_basket_price'][$basket_position]; $newprice=($oldprice/$oldamount)*$amount; $_SESSION['ses_basket_price'][$basket_position]=$newprice; }else{ $_SESSION['ses_basket_name'][]=$_GET['basket']; $_SESSION['ses_basket_amount'][]=1; $_SESSION['ses_basket_price'][]=$_GET['price']; $_SESSION['ses_basket_id'][]=$_GET['id']; $_SESSION['ses_basket_items']++; } }else{ $_SESSION['ses_basket_items']=1; $_SESSION['ses_basket_name'][0]=$_GET['basket']; $_SESSION['ses_basket_amount'][0]=1; $_SESSION['ses_basket_price'][0]=$_GET['price']; $_SESSION['ses_basket_id'][0]=$_GET['id']; session_register("ses_basket_items"); session_register("ses_basket_name"); session_register("ses_basket_amount"); session_register("ses_basket_price"); session_register("ses_basket_id"); } } if ($_SESSION['ses_basket_items']>0){ for ($basket_counter=0;$basket_counter<$_SESSION['ses_basket_items'];$basket _counter++){ // basket output $price=sprintf("%01.2f",$_SESSION['ses_basket_price'][$basket_counter]); $amount=$_SESSION['ses_basket_amount'][$basket_counter]; $name=$_SESSION['ses_basket_name'][$basket_counter]; $aaa=$basket_counter; echo "$amount $name $price"; echo "DEL"; echo "-sub"; echo "$aaa"; echo "\n"; } } else { $_SESSION['ses_basket_items']=0; unset($_SESSION['ses_basket_name']); unset($_SESSION['ses_basket_amount']); unset($_SESSION['ses_basket_price']); unset($_SESSION['ses_basket_id']); } ?>
RE: [PHP] array, trouble updating
Jason, Thx. Even though I have what I need for the client (I finally got things to work as desired), I'll rework it and update the client version. I knew I was doing things poorly and it degenerated into simply "get the damn thing to work." Thx, Mayo -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 17, 2005 5:56 PM To: php-general@lists.php.net Subject: Re: [PHP] array, trouble updating On Tuesday 17 May 2005 21:18, mayo wrote: > I usually work with cold fusion and took on a little project to get my > feet wet in php and am spinning my wheels. What I thought might be > difficult was easy and what I thought would be a piece of cake has > caused me much grief over the last few days. It appears that your overall problem is a misunderstanding of how arrays work in PHP and how easy it is to manipulate them. First: > if (session_is_registered('ses_basket_items')){ In general, for practical purposes (if PHP is installed using the recommended default setup, ie register_globals disabled), session_is_registered() is deprecated and should not be used. Use: if (isset($_SESSION['ses_basket_items'])) { ... }; Second: > if ($action == "empty") > { > while ($ses_basket_items > -1) > { > array_splice ($ses_basket_name, > $ses_basket_items, 1); > array_splice ($ses_basket_amount, > $ses_basket_items, 1); > array_splice ($ses_basket_price, > $ses_basket_items, 1); > array_splice ($ses_basket_id, > $ses_basket_items, 1); > $ses_basket_items--; > } > } You seem to be using multiple single dimension arrays to store your basket details. That is not the optimal way of doing things. You should have a *single* multi dimension array, there are many ways to do this, here's a couple: 1) $basket[1] = array('name' => 'name of product', 'id' => 'product id', 'price' => 'price of product', 'amount' => 'quantity required'); $basket[2] = array('name' => 'name of product', 'id' => 'product id', 'price' => 'price of product', 'amount' => 'quantity required'); 2) $basket['a_product_id'] = array('name' => 'name of product', 'price' => 'price of product', 'amount' => 'quantity required'); $basket['another_product_id'] = array('name' => 'name of product', 'price' => 'price of product', 'amount' => 'quantity required'); OK, so how do you operate on them? In the examples below 2 forms will be given corresponding to how you defined the arrays as per above. To remove an item: 1) unset($basket[n]); // where n is an integer 2) unset($basket['product_id']; // if product_id is an integer // then you don't need the single-quotes // note that also applies when first // define the array, ie: // $basket[product_id] = array(...); To change an attribute, eg the amount: 1) $basket[n]['amount'] = 5; 2) $basket['product_id'] = 10; To display an attribute, eg price: 1) echo $basket[n]['price']; 2) echo $basket['product_id']['price']; When playing around with arrays, print_r() is your friend, use it liberally. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- New Year Resolution: Ignore top posted posts -- 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] array, trouble updating - SOLVED
Yikes, Who would have thought something so easy would be such a pain in the butt. I solved it with embedded if-else clauses. Thx all -Original Message- From: mayo [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 17, 2005 9:19 AM To: 'php' Subject: [PHP] array, trouble updating I usually work with cold fusion and took on a little project to get my feet wet in php and am spinning my wheels. What I thought might be difficult was easy and what I thought would be a piece of cake has caused me much grief over the last few days. I'm making a little shopping basket, writing the results to a file, ftping the file to a distributor and sending the CC data to merchant services company. Write to file - easy FTP file to distributor - easy Updating the array in the shopping basket -- not so easy !!??!! A shopping basket should be able to add and delete items (done) You should be able to delete the whole basket (done) Now I need to be able to update quantity - I've spent at least 5 or 6 hours on this and have gotten nowhere!!! This learning exercise is getting to be a major time drag. Any hints would be good. The code is below: -1) { array_splice ($ses_basket_name, $ses_basket_items, 1); array_splice ($ses_basket_amount, $ses_basket_items, 1); array_splice ($ses_basket_price, $ses_basket_items, 1); array_splice ($ses_basket_id, $ses_basket_items, 1); $ses_basket_items--; } } if ($action2 == "deleteItem") { array_splice ($ses_basket_name, $position, 1); array_splice ($ses_basket_amount, $position, 1); array_splice ($ses_basket_price, $position, 1); array_splice ($ses_basket_id, $position, 1); $ses_basket_items--; } ?> 0){ foreach ($_SESSION['ses_basket_name'] as $basket_item){ if ($basket_item==$_GET['basket']){ $double=1; $subtract=1; $basket_position=$basket_position_counter; } $basket_position_counter++; } } if ($double==1){ $oldamount=$_SESSION['ses_basket_amount'][$basket_position]; $_SESSION['ses_basket_amount'][$basket_position]++; $amount=$_SESSION['ses_basket_amount'][$basket_position]; $oldprice=$_SESSION['ses_basket_price'][$basket_position]; $newprice=($oldprice/$oldamount)*$amount; $_SESSION['ses_basket_price'][$basket_position]=$newprice; }else{ $_SESSION['ses_basket_name'][]=$_GET['basket']; $_SESSION['ses_basket_amount'][]=1; $_SESSION['ses_basket_price'][]=$_GET['price']; $_SESSION['ses_basket_id'][]=$_GET['id']; $_SESSION['ses_basket_items']++; } }else{ $_SESSION['ses_basket_items']=1; $_SESSION['ses_basket_name'][0]=$_GET['basket']; $_SESSION['ses_basket_amount'][0]=1; $_SESSION['ses_basket_price'][0]=$_GET['price']; $_SESSION['ses_basket_id'][0]=$_GET['id']; session_register("ses_basket_items"); session_register("ses_basket_name"); session_register("ses_basket_amount"); session_register("ses_basket_price"); session_register("ses_basket_id"); } } if ($_SESSION['ses_basket_items']>0){ for ($basket_counter=0;$basket_counter<$_SESSION['ses_basket_items'];$basket _counter++){ // basket output $price=sprintf("%01.2f",$_SESSION['ses_basket_price'][$basket_counter]); $amount=$_SESSION['ses_basket_amount'][$basket_counter]; $name=$_SESSION['ses_basket_name'][$basket_counter]; $aaa=$basket_counter; echo "$amount $name $price"; echo "DEL"; echo "-sub"; echo "$aaa"; echo "\n"; } } else { $_SESSION['ses_basket_items']=0; unset($_SESSION['ses_basket_name']); unset($_SESSION['ses_basket_amount']); unset($_SESSION['ses_basket_price']); unset($_SESSION['ses_basket_id']); } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] multiple inserts into a db
I'm putting ordered items into a db. The information is stored in session variables. Session_variable_with_itemID_has(1001,1002,1003,1004) however when inserted into the db only 0,0,0,0 is recorded. Assuming that this was the 40th recorded order the table should look like this TABLE: orderedItems orderedItemsID -- orderID - itemID 159 - 40 - 1001 160 - 40 - 1002 161 - 40 -- 1003 162 - 40 - 1004 What comes out is: orderedItemsID -- orderID - itemID 159 - 40 - 0 160 - 40 - 0 161 - 40 -- 0 162 - 40 - 0 The loop itself works as intended. However it is not inserting this variable. $ses_basket_items is the total number of items $orderID = the orderID which these items are a part of $ses_basket_id = is the itemID number for ($i=0;$i<$ses_basket_items;$i++){ $query = "INSERT INTO orderedItems (orderID,itemID) VALUES ('$orderID','$ses_basket_id')"; mysql_query($query) or die('Error, insert query failed'); } mysql_close($conn); thx
[PHP] ftp_fput() "limit is 10 characters
I'm trying to ftp a file. I looked in the php manual and I don't see a character limit for ftp_fput(). I'm getting the following error ftp_fput(): Specified object name too long, limit is 10 characters: CF-20050520. in /home/www/cf/test.php on line 45 There was a problem while uploading CF-20050520.txt thx mayo
[PHP] multiple queries, one transaction
I have a site where I need to do multiple queries in sequence. I see there is a way to do consider all querys and to fail the entire procedure if one query fails. It's a BEGIN and COMMIT statement. mysql_query("BEGIN"); // starts the transaction mysql_query("COMMIT"); // ends the transaction I'm just not certain how it's used. Thx, mayo
[PHP] problems with spam
Has anybody else been getting spammed with penis and breast enlargeners to their listserv email? I use [EMAIL PROTECTED] solely for listservs and in the past week I've started getting 5-10 spams a day. Gil Midonnet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] problems with spam
I expected it. That's why I use a variety of email. However for over a year this address has been clean and then wham -- I get slammed. To me it's an indication that at least one of the listserv has been harvested. I'm trying to locate the listserv and contact the admin. Gil Midonnet > -Original Message- > From: Stuart [mailto:[EMAIL PROTECTED] > Sent: Monday, February 16, 2004 9:49 AM > To: mayo > Cc: php-general > Subject: Re: [PHP] problems with spam > > > mayo wrote: > > Has anybody else been getting spammed with penis and breast > enlargeners to > > their listserv email? > > Always. > > > I use [EMAIL PROTECTED] solely for listservs and in the > past week I've > > started getting 5-10 spams a day. > > What did you expect when you posted to a public mailing list? > > -- > Stuart > > -- > 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: Re[2]: [PHP] problems with spam
well, Interestingly enough I found the listserv. It's not one of the PHP lists in case you're interested. As for my email being harvested because I wrote it out ([EMAIL PROTECTED]). Well I'll change it to something else. :-) Regarding deleteing and filtering. You bet like everyone else who belongs to numerous listservs I hit the delete button often. It wasn't surprise -- it was trying to pinpoint the listserv and give a heads up. As it is members of one listserv has gotten swamped. The response there was a deluge of "me too!" Gil Midonnet > -Original Message- > From: Richard Davey [mailto:[EMAIL PROTECTED] > Sent: Monday, February 16, 2004 10:46 AM > To: mayo > Cc: php-general > Subject: Re[2]: [PHP] problems with spam > > > Hello mayo, > > Monday, February 16, 2004, 3:36:55 PM, you wrote: > > m> I expected it. That's why I use a variety of email. However > for over a year > m> this address has been clean and then wham -- I get slammed. > To me it's an > m> indication that at least one of the listserv has been > harvested. I'm trying > m> to locate the listserv and contact the admin. > > There are probably spam bots out there that harvest the PHP list > daily. I'm not sure what you expect any listserv admin to do about it > though, by their very nature this is unavoidable. > > -- > Best regards, > Richard Davey > http://www.phpcommunity.org/wiki/296.html > > -- > 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] printf() in a variable, or alternative to printf()
I need to be able to format data. Printf() is perfect because I need a certain amount of characters (30 for address). However I need this formatted data to be inside a file that's fwrite() and then FTPed to a distributor who will parse it and input into their database. printf("% 4d",$orderID[0]); does not work in $thisContent=" "data" . "moredate" . "evenmoredata" . "; In effect I need the output of printf() to be placed inside a variable and I don't see how to do that. Str_pad(), of course, does not work. Thx for any hints. mayo
RE: [PHP] printf() in a variable, or alternative to printf() - SOLVED
Thx, It's amazing how sleep helps. Couldn't believe that when I read sprintf() I didn't see how it did exactly what I was looking for. Thx all mayo -Original Message- From: mayo [mailto:[EMAIL PROTECTED] Sent: Thursday, May 26, 2005 11:35 PM To: php-general@lists.php.net Subject: [PHP] printf() in a variable, or alternative to printf() I need to be able to format data. Printf() is perfect because I need a certain amount of characters (30 for address). However I need this formatted data to be inside a file that's fwrite() and then FTPed to a distributor who will parse it and input into their database. printf("% 4d",$orderID[0]); does not work in $thisContent=" "data" . "moredate" . "evenmoredata" . "; In effect I need the output of printf() to be placed inside a variable and I don't see how to do that. Str_pad(), of course, does not work. Thx for any hints. mayo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] FW: write to file, difficulty inputting data
I'm writing customer orders into a file. I'm 1. getting data from session variables and a database, 2. putting it into a variable called $fileContent 3. then touch($filename); 4. then writing $fileContent to $filename - the code is at the bottom The test versions of this have all gone well. The file must contain the data in a preset format. All the data is on one line (no line breaks) and each field has a preset limit, The file is FTPed and the data parsed. So far so good. It works with one customer order Now when I want to write multiple customer orders it doesn't work? Abbreviated code is below // CODE FOR MULTIPLE ORDERS while($row = mysql_fetch_array( $result )) { $theItemID=$row["orderedItems.itemID"]; $theItemPrice=$row["itemPrice"]; $theItemQty=$row["itemQty"]; $thisItemID= sprintf("% 6d",$theItemID); $thisItemPrice= sprintf("%7.2f",$theItemPrice); $thisItemQty= sprintf("% 7d",$theItemQty); $moreContent= "\n" . "20" . $thisOrder . $thisItemID . $thisItemPrice . $thisItemQty . "\n"; } //END CODE // CODE BELOW IS FOR WRITE TO FILE // Make sure the file exists and is writable first. if (is_writable($filename)) { // Open $filename in write mode. if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } // Write $fileContent to opened file. if (fwrite($handle, $fileContent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle);
RE: [PHP] FW: write to file, difficulty inputting data
I need to write to file. After getting a customer's order I'm sending a file to a distribution company. The company wants all the information in a preset format which they will then parse. The problem comes when I try to put in multiple orders. In other words how does one use while($row = mysql_fetch_array( $result )) { } inside a variable -- or put the results into said variable The process I've set up is: 1. get data from session variables, $_POST and a database (this orderID, itemsOrdered and customerAddress, etc...) 2. put it into a variable called $fileContent 3. then write $fileContent to $file Example below: $thisOrder= sprintf("%12d",$orderID[0]); ... $fileContent= $thisOrder . $_POST["shippingMethodName"] . $a . $b . $c ; // end of $fileContent Now, I would like to put my orders into $fileContent. How does one place the output of while($row = mysql_fetch_array( $result )) { } into $fileContent? Thx. Mayo -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 01, 2005 1:13 AM To: mayo Cc: php-general@lists.php.net Subject: Re: [PHP] FW: write to file, difficulty inputting data On Tue, May 31, 2005 5:32 pm, mayo said: > if (!$handle = fopen($filename, 'w')) { This will WIPE OUT the existing file, and write a *NEW* file, from 0, starting from scratch. So you'll never have anything but the LAST item. You could use "a+" to append to the end of the file... But you *SHOULD* be using a database to avoid concurrency issues. You're going to have a MUCH better application if you store your data in the database, and it's EASIER than messing with a file. Only use a file if a database is absolutely forbidden by outside factors. Like badly-design homework assignments. Or not-very-smart pointy-haired-bosses. -- Like Music? http://l-i-e.com/artists.htm -- 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] write to file question, rewritten
I'm trying to write the results of a mysql_fetch_array db query to a file and am unable to. I'm putting the results into a variable $fileContent and then using fwrite(). I would have liked to do something like: $filecontent = . $result = mysql_query( " SELECT orderedItems.*, items.* FROM orderedItems, items WHERE orderedItems.orderID=$orderID[0] AND orderedItems.itemID=items.itemsID "); while($row = mysql_fetch_array( $result )) { $theItemID=$row["orderedItems.itemID"]; $theItemPrice=$row["itemPrice"]; $theItemQty=$row["itemQty"]; $thisItemID= sprintf("% 6d",$theItemID); $thisItemPrice= sprintf("%7.2f",$theItemPrice); $thisItemQty= sprintf("% 7d",$theItemQty); $thisOrder . $thisItemID . $thisItemPrice . $thisItemQty . } "; // end of $filecontent but that doesn't work. Mayo
RE: [PHP] Delay?
My average post takes 2+ hours. mayo -Original Message- From: Chris W. Parker [mailto:[EMAIL PROTECTED] Sent: Thursday, June 02, 2005 4:22 PM To: Chris Boget; Jason Sweeney Cc: php-general@lists.php.net Subject: RE: [PHP] Delay? Chris Boget <mailto:[EMAIL PROTECTED]> on Thursday, June 02, 2005 12:16 PM said: >>> Has anyone else noticed significant delays in messages getting >>> posted? No, no delay on my end. > > At least 4hrs on my end... Uhh.. I think he was joking... Take another read of his next sentence. :) Chris. -- 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] Invoke PHP script from onLoad handler?
Sorry if this has come up before. I want to update a select list from a mySql database whenever the browser window gets the focus. This is because I anticipate that the user will frequently use a second window to make additions to the database that holds the list values while filling in the form, and I want those additions to be in the select list when the user returns. At present I have PHP querying the db before I output the body tag, and an onLoad() handler passes the returned records to a Javascript which populates the list box with the query results, but I have only figured out how to query the db when the page initially loads. I really need to query the db and invoke the Javascript every time the window gets focus. So, I guess my question is twofold: can I invoke a php function with an onLoad handler, and if so, how can I have onLoad do both things - run the php function to query the database, then run the Javascript to populate the list box? Or is there another way? TIA, Chuck Mayo -- 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]
[PHP] Get text between
I need some help with a program, I need to get every instance of text between GET TEXT HERE and save the results in a variable. Does anyone have some example code of how to do it along with how to put the results into just one variable? __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.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] Invoke PHP script from onLoad handler?
OK, I've gone back through the archives and now understand the situation with client- and server-side. I just wasn't thinking it through. Spawning a window to let PHP query the db and somehow passing returned values back to the parent window is something I could do, I suppose, but it seems that what I and the other zillion people who keep asking the same question need is a way to get to our databases using a client-side technology like Javascript. I recognize the shortcomings of client-side stuff like compatility issues and on/off preferences and in this case am willing to let the user take some reponsibility for his browsing experience. Now I'm completely off-topic, but does anyone have any ideas regarding database access with Javascript, perhaps by having JS run a shell or perl script? How would JS get the values back? Something like function getdb () { var mylist = execute.some.remote.program(./getmysqldata.pl); } With all the traffic on this type of request, I'm surprised the FAQ doesn't take up the subject. Thanks, Chuck - Original Message - You *can* have a JavaScript handler invoke PHP -- but it requires accessing a URL and waiting for the web-server to respond, so your response time will not be so hot. I'm afraid I don't recall how, but it has been posted here before... -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm - Original Message - From: Chuck Mayo <[EMAIL PROTECTED]> Newsgroups: php.general Sent: Friday, January 26, 2001 10:10 AM Subject: [PHP] Invoke PHP script from onLoad handler? > Sorry if this has come up before. > > I want to update a select list from a mySql database whenever the > browser window gets the focus. This is because I anticipate that the > user will frequently use a second window to make additions to the > database that holds the list values while filling in the form, and I > want those additions to be in the select list when the user returns. > > At present I have PHP querying the db before I output the body tag, and > an onLoad() handler passes the returned records to a Javascript which > populates the list box with the query results, but I have only figured > out how to query the db when the page initially loads. I really need to > query the db and invoke the Javascript every time the window gets focus. > > So, I guess my question is twofold: can I invoke a php function with an > onLoad handler, and if so, how can I have onLoad do both things - run > the php function to query the database, then run the Javascript to > populate the list box? Or is there another way? > > TIA, > Chuck Mayo -- 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] Invoke PHP script from onLoad handler?
This is an interesting idea - I hadn't considered having the second window be subordinant to the first, and really didn't even know I could pass data between windows. I'll play with this, it might work out. Thanks, Chuck Jonathan Sharp wrote: > I wrote a browser based application (yes it is an application!) (but I can't > let you see it cause it's propriatary technology) but the client side was > javascript and I had PHP save the data and read data... > > I won't go into detail, but basically I had PHP print JavaScript, and then > have a variable in the main window that the child window would save the new > data to... > > for example, have the javascript (which PHP generates) be something like > > var DATAARY = new Array(); > DATAARY[0] = 'Some data'; > DATAARY[1] = 'Some data'; > DATAARY[2] = 'Some data'; > DATAARY[3] = 'Some data'; > window.parent.document.MAINDATAARY = DATAARY; > > It was something to that extent, it works quite nicely, and it definetly > pushes the limits of the technology used. > > -Jonathan Sharp > > Director of Technology - Imprev Inc. > Renwick Development Group - Flyerware > http://www.flyerware.com/ > Phone: (425)688-9200 > Cell: (425)766-1398 > EPage: [EMAIL PROTECTED] > > -Original Message- > From: Chuck Mayo [mailto:[EMAIL PROTECTED]] > Sent: Saturday, January 27, 2001 4:05 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] Invoke PHP script from onLoad handler? > > OK, I've gone back through the archives and now understand the situation > with client- and server-side. I just wasn't thinking it through. > > Spawning a window to let PHP query the db and somehow passing returned > values back to the parent window is something I could do, I suppose, but > it seems that what I and the other zillion people who keep asking the > same question need is a way to get to our databases using a client-side > technology like Javascript. > > I recognize the shortcomings of client-side stuff like compatility > issues and on/off preferences and in this case am willing to let the > user take some reponsibility for his browsing experience. > > Now I'm completely off-topic, but does anyone have any ideas regarding > database access with Javascript, perhaps by having JS run a shell or > perl script? How would JS get the values back? Something like > > function getdb () { >var mylist = execute.some.remote.program(./getmysqldata.pl); >} > > With all the traffic on this type of request, I'm surprised the FAQ > doesn't take > up the subject. > > Thanks, > Chuck > > - Original Message - > You *can* have a JavaScript handler invoke PHP -- but it requires > accessing > a URL and waiting for the web-server to respond, so your response time > will > not be so hot. > > I'm afraid I don't recall how, but it has been posted here before... > > -- > Visit the Zend Store at http://www.zend.com/store/ > Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm > Volunteer a little time: http://chatmusic.com/volunteer.htm > - Original Message - > From: Chuck Mayo <[EMAIL PROTECTED]> > Newsgroups: php.general > Sent: Friday, January 26, 2001 10:10 AM > Subject: [PHP] Invoke PHP script from onLoad handler? > > > Sorry if this has come up before. > > > > I want to update a select list from a mySql database whenever the > > browser window gets the focus. This is because I anticipate that the > > user will frequently use a second window to make additions to the > > database that holds the list values while filling in the form, and I > > want those additions to be in the select list when the user returns. > > > > At present I have PHP querying the db before I output the body tag, > and > > an onLoad() handler passes the returned records to a Javascript which > > populates the list box with the query results, but I have only figured > > > out how to query the db when the page initially loads. I really need > to > > query the db and invoke the Javascript every time the window gets > focus. > > > > So, I guess my question is twofold: can I invoke a php function with > an > > onLoad handler, and if so, how can I have onLoad do both things - run > > the php function to query the database, then run the Javascript to > > populate the list box? Or is there another way? > > > > TIA, > > Chuck Mayo > > -- > 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] > > -- > 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] -- 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]
[PHP] VIRUS ON LIST?
I don't want to be an alarmist, but wanted to give everyone a heads-up. Our firewall at corporate scrubbed a virus from a mail sent to the php-db list from "Angel2 Gabriel Lena Valega". The virus was in an attachment named "Emanuel.exe" and the message subject was "i need help with odbc!" John Coonrod wrote: > Right. That's what I saw here also: a virus attachment from Angel2 Gabriel > Lena Valega in Peru > > = Original Message from Chuck Mayo <[EMAIL PROTECTED]> at 1/29/01 6:17 pm > >Virus in this mail? > > > >Angel2 Gabriel Lena Valega wrote: > > > >> -- Virus Warning Message (on the network) > >> > >> Found virus TROJ_NAVIDAD.E in file Emanuel.exe > >> The file is deleted. > >> > >> - > >> > >> > >> > >> -- Virus Warning Message (on the network) > >> > >> Emanuel.exe is removed from here because it contains a virus. > >> > >> - > > > > > >-- > >PHP Database 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] > > > Dr. John Coonrod, Vice President, [EMAIL PROTECTED] > The Hunger Project, 15 East 26th Street, NY, NY 10010 www.thp.org -- 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]
[PHP] Preserve variables between page loads?
This may have crossed the list a bazillion times, but I couldn't really find anything appropriate in the archives... maybe I just didn't look hard enough. In a MySQL app, I have the usual row of paging links at the bottom of the page and need to pass to the next iteration more variables than I can comfortably url-encode in the hyperlink. If all these paging links were submit buttons I could pass anything I wanted in hidden form fields, but since they're hyperlinks I don't seem to have that option. Is there a way to selectively preserve variables between iterations? Something like variables that are global to PHP, as opposed to being global within the script? -- 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] Preserve variables between page loads?
Sounds like just what I need. Thanks, Ankur & Maxim. Ankur Verma wrote: > try using session variables. > > take a look at phplib if you are using PHP3 or > > http://www.php.net/manual/en/ref.session.php > > if you are using PHP4 > > hope that helps > > Ankur Verma > HCL Technologies > A1CD, Sec -16 > Noida, UP > India > > - Original Message - > From: "Chuck Mayo" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, February 12, 2001 10:53 AM > Subject: [PHP] Preserve variables between page loads? > > > This may have crossed the list a bazillion times, but I couldn't > really > find > > anything appropriate in the archives... maybe I just didn't look hard > enough. > > > > In a MySQL app, I have the usual row of paging links at the bottom of > the > page > > and need to pass to the next iteration more variables than I can > comfortably > > url-encode in the hyperlink. If all these paging links were submit > buttons > I > > could pass anything I wanted in hidden form fields, but since they're > > hyperlinks I don't seem to have that option. > > > > Is there a way to selectively preserve variables between iterations? > Something > > like variables that are global to PHP, as opposed to being global > within > the > > script? > > > > > > -- > > 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] > > -- > 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] -- 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]