Jump to content

tomccabe

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by tomccabe

  1. I have an XML file like such: <spice> <sections> <contact></contact> <products></products> <people></people> <homes></homes> <harvest></harvest> <contactCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </contactCopy> <homesCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </homesCopy> <productsCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </productsCopy> <peopleCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </peopleCopy> <harvestCopy> <banners><![CDATA[Lots of <u>text</u> with tons of <a href="#">links</a> and <i>other</i> markup.]]></banners> </harvestCopy> </sections> </spice> What I need to be able to do is pull the CDATA content out, WITH the tags intact, have the client edit the content with a markup editor and put unentitied HTML back into the CDATA section. Sorry for being all over the place! I've been up all night trying to solve this stupid problem for a stupid Flash site.
  2. $doc = new DomDocument(); $file = "spice.xml"; $doc->load($file); $homesCopy = $doc->getElementsByTagName("homesCopy")->item(0); $banners = $homesCopy->firstChild; $doc->removeChild($banners); "Argument 1 passed to DOMNode::removeChild() must be an instance of DOMNode"
  3. Yup, I've been looking at this, but it's all very confusing. I have a deadline of today and the only thing I can't get to function is the CDATA section. Starting to freak out because most of my searching leads me down wildly different paths, some with "createCDATASection", some using an XPath object, some traverse the document with getElementByTagName...I am able to echo the CDATA section I want to be able to edit, but can't seem to get removeChild to work (granted I'm trying to absorb all of this at a rapid pace). Here's what I have so far: $doc = new DomDocument(); $file = "spice.xml"; $doc->load($file); $xPath = new DomXPath($doc); $homesCopy = $xPath->query("//sections/homesCopy"); echo $homesCopy->item(0)->nodeValue; I get the tags in the CDATA section to output as html here which is great. Now if only I could edit it
  4. If I don't use that option none of the text from the CDATA sections is pulled out on the load.
  5. I'm tearing my hair out trying to work with "simple" XML for the first time. I'm building a small CMS for a Flash based site and the content is held in an XML file. My problem is that many of the copy fields are XML CDATA fields. On the one hand, with: $xml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA); I can pull the data out of that node and the CDATA tags are stripped. My issues come with trying to save the data with: file_put_contents($file, $xml->asXML()); Problems are: a) tags are interpreted with their HTML entity equivalents. I don't want this to happen as it's a CDATA field being read by Flash. I gather this is coming from the asXML method because even if I do an html_entity_decode on the $_POST data it's still being converted. b) because of the above, there's no way to add the CDATA tags because they also have their charachters converted. SimpleXML so far has been anything but simple for me Has anyone ever run into this? Is there a way to save the file back in a way that will just keep my data exactly as is and also allow me to add the CDATA tags back in?
  6. I set the first condition of the while loop for a state matching the GeoCity state (the only other field they share) and that's shaved a little bit of time off (getting about 3500 - 5500ms on firebug now), but now my interest is also peaked! This stupid banner is actually turning into a fun little project haha.
  7. Yeah, porno, you are absolutely correct. Unfortunately this banner is one that will display the weather at the user's location and that API needs zip code data, not simply city. I had no problem getting the city data as soon as HTH pointed me to GeoCity. The problem is that they only have zip codes for about half their records. Not too helpful a majority of the time (for instance no zip for me in Hollywood or partner doing the Flash portion in NYC). That said, I did solve my problem and will post my solution for anyone else that might come across this here or through Google (and feel free to tell me if it could be more efficient! I'm sure there are ways I might cut down on query time of the CSV). I did indeed do it by latitude and longitude and used the CSV file with zip codes/lat/lon located here (as suggested by GeoCity FAQ): http://geocoder.ibegin.com/downloads.php The script cuts out before using the CSV if the IP has a zip code record in the GeoCity database, so it only adds the query time if it absolutely needs to (and it is about a full second). <?php include("geoipcity.inc"); include("geoipregionvars.php"); // OPEN GEOCITY DATABASE $gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD); // IP CHECKS if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } // GET GEOCITY LOCATION DATA FROM IP $record = geoip_record_by_addr($gi,$ip); // IF ZIP IS LOCATED IN GEOCITY DATABASE, RETURN if ($record->postal_code) { return $record->postal_code; } // IF NOT RESOLVE ZIP CODE BY LATITUDE/LONGITUDE & RETURN else { $lat = $record->latitude; // save GeoCity latitude $lon = $record->longitude; // save GeoCity longitude $row = 0; // start at first row of zip code file $diff = 10; // init out of bounds difference $open = fopen("zips.csv", "r"); // open zip code file while (($data = fgetcsv($open, 1000, ",")) !== FALSE) { // check records $test = abs($data[3] - $lat) + abs($data[4] - $lon); // get total difference between this record and actual lat/lon if (($test < 10) && ($test < $diff)) { // if it's reasonably close and less than the current lowest $diff = $test; // reset lowest record $zip = $data[0]; // set this zip as current } } return $zip; } // IF NO RESULT FROM EITHER, RETURN NYC DEFAULT if ($zip == NULL) { $default = "10001"; return $default; } geoip_close($gi); ?>
  8. After a bit more digging I found the fgetcsv() function. Seems to be what I'm after. Here's the steps I think this needs to take: 1. Run ip search on geoip database. 2. if {find match with zip} return zip -task complete in this case 3. else {take lat/long from geoip. Run csv query on csv file. Check each entry's lat/long. Get sum of abs value of difference between lats and abs value of difference between long. Return zip from record with lowest total difference. The portions in bold which specifically deal with the csv records is where I'm stumped. The examples in the php manual are not all that helpful for my situation.
  9. Hey HTH, This was great...gives me *almost* what I need. I've got it looking up city/state at this point, but their database doesn't actually have zip codes. They explain this as such: The site this points to has a great csv file with zip codes that is totally fine (weather difference won't be that crazy if I'm off by 25 miles...it doesn't need to be a scientific match). Throughout searching I've vaguely gotten the idea that you can run an SQL query on a csv file (maybe I'm getting that wrong). I do know you can import one into an SQL database, but as this will be an advertisement the server won't necessarily have SQL installed. What are my options? I'm so close I just need to figure out how to interface these 2 pieces of data! Arrrghhhh!!!
  10. I have to write a script for some banners that need to be returned the user's zip code...anyone have any idea how to do this? :'(
  11. I have a couple specific questions as I work to get more efficient/complex with my MySQL queries. In this specific project I have 3 related tables: products, categories and prod_cats. The last table functions essentially as a go between for category and position values (i.e. each product can be in multiple categories and has a specified position in each category). - 1st question: I have working PHP methods that add new categories and products. For instance the category one finds out how many rows are in the categories table in one query and assigns that value+1 to a variable, then adds that as the position, plus the category name to the table in another query. What I would like to do is roll this into one query. I tried things along the lines of: INSERT INTO categories (category, position) VALUES ('$category', (SELECT MAX(position) FROM categories)+1) This returned the error: "You can't specify target table 'categories' for update in FROM clause". It would be helpful to find any way to do this sort of operation. - 2nd Question: Well I answered this while posting this, but I thought I'd post where I found it in case it helps someone else. I was trying to find uncategorized products (no rows in the prod_cats table would have that product ID but the product does exist). This is for orphaned products after categories are deleted, etc or for products that the client doesn't want to bother categorizing while entering a batch. Obviously there's tons of other reasons to want to find something that is in one table but not another in relational databases. It uses NOT IN plus a subquery (it doesn't make a ton of sense to me why the subquery there does what it does, but hey, I'm learning). http://ocaoimh.ie/mysql-finding-the-records-in-one-table-that-are-not-in-another-table/
  12. Should I be doing more than this?
  13. I'm using sessions, yes. Security is a pretty new and confusing topic for me. I register a session variable when someone logs in and each page checks to see if that variable is set.
  14. I'm working through SSL stuff for the first time. I just want to know if I should secure my entire CMS or simply the login page? The only thing really happening in the CMS is adding/editing products for a store. Actually, there's the ability to view/print orders, but not edit the info. I know on the client side that I'll be securing my login/register/checkout pages, but I'm a little confused on how much of the backend needs SSL.
  15. I think I've found the solution to this. Paypal's Website Payments Pro API. Looks like a giant pain, but it achieves the intended purpose.
  16. This is sort of what I'm looking to do, but with a multiple item cart: http://net.tutsplus.com/tutorials/php/using-paypals-instant-payment-notification-with-php/ I'll try to look for some more info I guess, but I figure I'm certainly not the first person to want to do this.
  17. Im just finishing up the front end to a client's shop who only has (and wants) to use Paypal as a payment method. I've never had to work with Paypal for multiple items and want to know if there's a tried and true method of doing this. My setup does all the shipping info and cart population (the items in the cart are in a $_SESSION array) what I would like to do is send my items into a Paypal shopping cart in which the items are individually shown with quantity, individual price, total price per item and total cart price with the payment option. I know about the Paypal IPN and figure this is part of the solution, but is there a common method for doing the above? I've found solutions for a single item. My workaround thought was to have the client make her Paypal "buttons" but just store the code in her products database with the rest of the info and store them as hidden input fields that shoot off to Paypal all at once. I wonder if this is even possible? I've tried to wade through Paypal's dev site but it's poorly laid out and I can't seem to find an answer.
  18. Well, all of this lead me to the solution. On this server the client can host more than one site. I was trying to put the file above that site's folder and I just used a couple ../ Thanks!!!
  19. I tried that and I couldn't get it to work. And I think I figured out why. I found this post http://roshanbh.com.np/2008/01/absolute-path-and-relative-path-file-inclusion-in-php.html and trying that method I was given an entirely different directory tree above the public folder. I think why your method didn't work is because I was trying to reverse through the wrong structure. I guess I need to figure out why these are giving entirely different directories: echo $_SERVER['DOCUMENT_ROOT']; echo dirname(__FILE__); I tried to reverse through again as you suggested with no luck. I CAN use the absolute path. My problem with that is that is goes something like: /services/webpages/util/2/r/CLIENTS-FTP-USERNAME.site.HOSTNAME/includes/config.php which gives away a whole lot of information, exactly the kind I am trying to protect. :'(
  20. I'm trying to include (or more accurately require_once) my database config file that is above the public folder on my server. I've read a lot of posts on people doing this but none of it seems to work for me. Each of my pages that require a DB connection call an include to my connection.php file which looks like this: <?php require_once 'config.php'; $connection = mysql_connect($db_hostname, $db_username, $db_password); if (!$connection) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database, $connection) or die("Unable to select database: " . mysql_error()); ?> That config file, which contains the actual login info is what I would like to grab from above the public area (right now it is in the same folder). If I echo out $_SERVER['DOCUMENT_ROOT'] on my shop's index page I get the following: /services/webpages/g/r/mysite.com/public/shop Where I've dropped a copy of my config.php file is (following this structure, though the "include" folder is at the top level of where I can access via FTP): /services/webpages/g/r/include/ I can't seem to call to this file from the many places I've looked at this. Among others, I've tried: require_once '/services/webpages/g/r/include/config.php'; to no avail. Does an absolute path not work with require? Is my path incorrect?
  21. Thanks Andrew. At least I know I configured it correctly. I think the issue is arising because I loaded the DB with a bunch of dummy products for development (the client is going to be populating the DB at which time I'll flush the current "products"). Most of them have the same name format. Duh. Good reading though to understand this!
  22. Hi all, I'm sort of a newbie PHP/MySQL developer learning some more complex stuff. Usually a good Google search can explain a feature, but I have had NO luck understanding FULLTEXT indexes/searching. Here's the table structure I'm trying to search from a search form: CREATE TABLE `products` ( `prod_id` int(5) NOT NULL AUTO_INCREMENT, `prod_title` varchar(128) NOT NULL, `live` varchar(3) NOT NULL DEFAULT 'no', `featured` varchar(3) NOT NULL DEFAULT 'no', `price` int(7) NOT NULL, `short_desc` varchar(400) NOT NULL, `long_desc` varchar(612) NOT NULL, `quantity` int(4) NOT NULL, `picture` varchar(3) NOT NULL, `pic_ext` varchar(4) NOT NULL, PRIMARY KEY (`prod_id`), FULLTEXT KEY `prod_title` (`prod_title`,`short_desc`,`long_desc`) ) ENGINE=MyISAM AUTO_INCREMENT=104 DEFAULT CHARSET=cp1257 ------------------------ Now what I've been trying to do is perform searches across the 3 fields under the FULLTEXT index (which, hell, I'm not even sure is set up correctly!) with multiple search terms. For instance: SELECT * FROM products WHERE MATCH(prod_title,long_desc,short_desc) AGAINST ('some words here') It seems to be able to grab certain words from certain fields and certain words it refuses to find. It's maddening and I'm probably not understanding how this works. Can anyone help?
  23. Hi, This is probably going to be a stupidly simple question to answer... I've got a script to reorder values in a table by dragging/dropping. The script works fine, but at this point I have to hard code the name of the table into the script. The table name comes through via the $_GET or $_REQUEST superglobal. My problem lies in the fact that multiple tables need to use this script, but the tables are dynamically created, so I need to be able to tell the script to use whatever table comes in from the superglobal. Here's my script which has one table hard coded into it: <?php // If reorder is submitted if (isset($_POST['update'])) { $size = $_POST['how_many']; for ($k=1; $k<=$size; $k++) { $old = $_POST[$k]; $query = "SELECT cat_id FROM categories WHERE position='$old'"; $result = mysql_query($query, $connection); confirm_query($result); $catids[$k] = mysql_fetch_row($result); } $i = 1; while ($i <= $size) { $new_value = $i; $id = $catids[$i][0]; $query = "UPDATE categories SET position='$new_value' WHERE cat_id='$id' LIMIT 1"; $result = mysql_query($query, $connection); confirm_query($result); $i++; } go_to("categories.php?redir=reorder"); } ?> <br /> <form name="update_position" method="post" action="reorder.php"> <?php // Runs on reorder drag $result = $_REQUEST["cat_table"]; $count = count($result); $how_many = $count - 1; for ($j=1; $j<=$how_many; $j++) { $old = $result[$j]; $new_value = $j; echo "<input type=\"hidden\" name=\"$new_value\" value=\"$old\" />"; } echo "<input type=\"hidden\" name=\"how_many\" value=\"$how_many\" />"; ?> <input type="hidden" name="update" value="yes" /> <input type="submit" value="Update Order" /> <input type="button" name="Cancel" value="Cancel" onclick="window.location='categories.php'" /> </form> A var_dump of the $_REQUEST variable on drag/drop produces these results: array(2) { ["cat_table"]=> array(6) { [0]=> string(0) "" [1]=> string(1) "2" [2]=> string(1) "1" [3]=> string(1) "3" [4]=> string(1) "4" [5]=> string(1) "5" } ["PHPSESSID"]=> string(32) "ddbea61cfd7f94763e03be50112369e4" } What I need to do is in the line $result = $_REQUEST["cat_table"]; set $result equal to whatever the table accessing the script is without having to refer to it by name because it may be different all the time based on what info is in the database. I googled around and couldn't find anyone explaining how to access superglobal data from array notation (which I assume is how to get it), nor could I figure it out by messing around with stuff like $_REQUEST[0][0], etc. Sorry if this is a dumb thing to ask. It seems so straightforward I'm sort of embarrassed that I can't figure it out!
  24. Thanks so much sasa, this worked perfectly! I'm still getting used to the fact that you can build queries like that. So simple! Thanks to both of you. The first reply was also really helpful and gives me some direction to understand the SQL array concept better. This was my first post here, a d usually it's crickets on many boards looking for help so I'm psyched to know this board is so great. I know I'll be spending a lot of time here and someday I hope I'll be able to give back the help that I'll obviously get here.
  25. Well, still no luck. Maybe I'm not understanding what is going on with this loop. I tried to implement as I thought it should. // DELETE if (isset($_POST['delete']) && isset($_POST['cat_id'])) { $cat_id = $_POST['cat_id']; $delete = "DELETE FROM categories WHERE cat_id='$cat_id' LIMIT 1"; $result_del = mysql_query($delete, $connection); confirm_query($result_del); // Reorder after delete // get all categories by position $get_cats = "SELECT * FROM categories ORDER BY position ASC"; $cats = mysql_query($get_cats, $connection); confirm_query($cats); // get number of rows in categories $rows = mysql_num_rows($result); //get ids of all categories $get_ids = "SELECT cat_id FROM categories ORDER BY position ASC"; $ids = mysql_query($get_ids, $connection); confirm_query($ids); // put id values into array $x=0; while ($ids) { $id_array[$x++]=mysql_fetch_array($ids[0]); } // reorder positions for ($j = 1; $j <= $rows; ++$j) { $row = mysql_fetch_row($result); $fetch = $id_array[$j-1]; $query1 = "UPDATE categories SET position='$j' WHERE cat_id='$fetch'"; $result1 = mysql_query($query1, $connection); confirm_query($result1); } } Still no luck. :'(
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.