Jump to content
Old threads will finally start getting archived ×

John_A

Members
  • Posts

    70
  • Joined

  • Last visited

Everything posted by John_A

  1. Thanks both for your input. As I said, it was a bespoke shopping cart script, that I inherited, which already had a Google feed but the sizes were in a comma separated list for each product (used to be OK with Google) but now needs to be one size per product. I wrote neither the initial script nor the google feed add-on. I've been tasked with this, and not a lot of time to do it. I'm already working on a local dev server, not the live site. TBH it would have taken me longer to do everything you suggest to ask the question "properly" than it did for me to fix it myself. I didn't explode the commas because the CSV list is built from another query on the database for the prodID, all individual rows as product options for size, so didn't see the point in building it again then exploding it to get back to where I started. It's a CSV in the original as that used to be OK with Google. I'm pretty sure I gave as much information as was needed to answer / help if someone was inclined to. In fact I posted a duplicate elsewhere, and it was answered with a solution - too late for me but it looked like it would have worked. Hey ho. Lesson learnt.
  2. OK, thanks for your help so far. Partially thanks to your input I changed my approach completely, now manipulating the feed as I create it line by line later in the same file, rather than messing with the array beforehand, and have it working just as I need. Hopefully, one day, I'll be as awesome as you and not need to ask for help. Stay safe, and thanks again!
  3. Going through the array for sizes was messing with the feed output later on, so I changed it to a foreach instead. The plan is for the first foreach loop to manipulate the product array as necessary, then once done a separate foreach going through the now correct array to output the feed. Here's the one I need to fix: - foreach ($result as $key => $thisProduct) { echo $thisProduct["prodID"] . '<br/>'; $thisproductSizes = ""; $sizesResult = $dbA->query("SELECT $ExtraFieldsValues.content From $ExtraFields, $ExtraFieldsValues Where $ExtraFields.name = 'size' and $ExtraFields.extraFieldID = $ExtraFieldsValues.extraFieldID and $ExtraFieldsValues.productID =".$thisProduct["prodID"]." Order By $ExtraFieldsValues.position"); $sizesCount = $dbA->count($sizesResult); for ($sf2 = 0; $sf2 < $sizesCount; $sf2++) { $sizesRecord = $dbA->fetch($sizesResult); $thisproductSizes .= ",".$sizesRecord["content"]; } if (strlen($thisproductSizes) > 0){ // there's at least one size so needs to be dealt with $thisproductSizes = substr($thisproductSizes,1); // do stuff here to make one product into many // each with item_group_id = prodID, // and id = prodID-xx (size), with only one size } else { $thisproductSizes = ""; } echo $thisproductSizes . '<br />'; } But, thinking about it, if there's only 1 size that's fine, it's if there's 2 or more that there'll be an issue...
  4. There probably is but it's for an automatic google product feed that will run once every month so efficiency isn't really a concern. It's part of a bespoke ecommerce script I inherited and can't really change much on, the table structures are what they are and can't be changed at this stage. So what I have is the $products array which includes most of the fields I need straight out of it, but the sizes needs to be a 2nd query within that. The $product array should be updated on-the-fly with duplicates where necessary with only one size in each, and the id and item group id updated too.
  5. It turns out I don't actually have the sizes in the $product array as above, they're a query within the loop that builds the feed in it's current state. $result is the query to fetch all products... $count = $dbA->count($result); for ($f = 0; $f < $count; $f++) { $record = $dbA->fetch($result); $productSizes = ""; $result2 = $dbA->query("SELECT $ExtraFieldsValues.content From $ExtraFields, $ExtraFieldsValues Where $ExtraFields.name = 'size' and $ExtraFields.extraFieldID = $ExtraFieldsValues.extraFieldID and $ExtraFieldsValues.prodID =".$record["prodID"]." Order By $ExtraFieldsValues.position"); $count2 = $dbA->count($result2); for ($f2 = 0; $f2 < $count2; $f2++) { $record2 = $dbA->fetch($result2); $productSizes .= ",".$record2["content"]; } if (strlen($productSizes) > 0){ $productSizes = substr($productSizes,1); } echo $productSizes . '<br/>'; } The $products array includes the other fields I referenced above along with quite a few others: - but does NOT include the item group id field, which should be added blank or populated as above for each product. I'm not sure if this makes it easier, or harder?
  6. I have an existing PHP array ($products) with various fields in it.... id / title / description / link / image link etc. etc. as per requirements for a Google Products feed (https://support.google.com/merchants/answer/7052112). My issue is that, for clothing, Google want a separate record for each size available. My array includes the "size" field as a comma separated list e.g. 6,8,10,12,14 or XS,S,M,L,XL etc. etc. So before creating the feed (a text file, which is currently outputting fine except for the size field issue) I need to duplicate each id where there's more than 1 size in that field, for each size, and then manipulate the fields a little so that (ignoring all the duplicated fields that would remain unchanged) instead of the single record : - id size item group id 52 6,8,10,12,14,16,18,20,22,24,26 I'd have 11 records, item group id would be what the id is, the size appended to the id, and the size field only one (in sequence of those from the original), so: - id size item group id 52-6 6 52 52-8 8 52 . .. ... 52-24 24 52 52-26 26 52 That's just one product....there are quite a lot, each with multiple sizes, but all in the same format within the $products array. As always, any help / pointers / solutions much appreciated!
  7. Nothing, everything is the same there are just slight differences in the way things are done sometimes, e.g. parsing xml as php the syntax is slightly different in .htaccess due to PHP setups differing slightly. 99.9% of the time everything is identical, but there are sometimes a few lines in a .htaccess file somewhere that just have to differ. I'm perfectly happy with the hosting I have, I pay for a managed service and it was actually myself who asked for Litespeed on the one in question, initially when it was touted as a faster, drop-in replacement for Apache but it's now evident that there are a few (rare cases) where things have to be done a little differently. I'm happy with the speed improvements that has brought, but at the same time don't want to mess with my dev server at this time as I have other sites live elsewhere that are not on Litespeed but use the same dev server. Anyway, it is what it is and I am where I am. I'm quite happy with my setup (dev and multiple live servers), I don't do anything over-complicated. It worked perfectly before this issue (for 10+ years) and hopefully using requinix's solution it will continue to do so - it's no great hardship going forward if I occasionally need to make a .htaccess.dev file if there's a difference between dev and production. All I asked for was a way to quickly clone the existing .htaccess files as per the OP
  8. OK, here's the background... I used to use an environment variable to enable me to differentiate between my dev and production server, using this in .htaccess: - <IfDefine DEV_SERVER> # dev server specific stuff here </IfDefine> <IfDefine !DEV_SERVER> # production server specific stuff here </IfDefine> The environment variable "DEV_SERVER" was only ever set on my dev server, and never on production, obviously. This approach worked a treat until my production server host installed Litespeed as a replacement for Apache. Litespeed doesn't like the above, and ignores everything. I tried having different versions of .htaccess files for dev and production, but that's messy and dangerous, I like to be able to interchange all files at any time between the two. My dev server runs Apache 2.4 and I have no plans to change this. I read that you can specify a different filename for .htaccess by putting this in httpd.conf: - AccessFileName .htaccess.dev But (I think) you can't set an order of preference here (like, say, DirectoryIndex), so I'm thinking the simplest solution so that I can have identical copies is have my dev server use .htaccess.dev instead of .htaccess - the production server will simply ignore any .htaccess.dev files. If there's no difference (there doesn't always need to be, it depends on the site and htaccess requirements) then the .htaccess (if there is one) can just be copied and renamed. The dev server will use .htaccess.dev and the live server will still use .htaccess. Problem is, I've manually done some already and so that's why if there is already a .htaccess.dev file then it should be left as is. ETA: I realise this is now no longer a PHP problem, even though my first thought was to do it with a PHP script, it seems that was probably the more complicated approach.
  9. Wow, if that works then that's excellent, thanks a lot! I'll backup all just in case!
  10. Around 200! It is just a 1 off though.
  11. I've got a dev server which, for reasons I won't go into, needs to have different .htaccess files for each site (and subfolders within them) within it. But not always. What I need to do is: - For the folder I put the PHP script in, and every folder under it (the whole tree under it): - If there's a .htaccess file an no .htaccess.dev file, copy .htaccess and name the copy .htaccess.dev (and look in subfolders) If there's a .htaccess file and also a .htaccess.dev file, do nothing (but keep looking for subfolders) If there's neither a .htaccess or .htaccess.dev file, do nothing (but keep looking for subfolders) I'd try to come up with something myself, but getting it wrong will be fairly catastrophic! I'm sure the conditional copy / rename bit is relatively straightforward, but it's the recursive searching of the whole file-system under the script's location that I'm not sure about... Any help greatly appreciated, as always! I have SSH access, if it's easier done that way maybe I'm approaching it wrong?
  12. Thanks again. It's part of a URL building function...to replace any non-alphanumeric characters with spaces, which are in turn replaced with dashes or underscores in the next part...
  13. Thanks for your reply Jacques1. I did check the manual before posting, and it says to use preg_replace_callback() instead. But if, as you say, the modifier in my code does nothing anyway, is my suggestion (i.e. to simply remove it) not the best approach in this case?
  14. I have this snippet which is giving a deprecated warning re the "e" pattern modifier in PHP5.5: - $result = preg_replace("/\[^a-zA-Z0-9]/e"," ",$result);I'm not even sure what the "e" modifier does, as it's not my code...maybe something to do with removing duplicates? Anyway, what's the best way to replace this so that it doesn't give the warning in PHP5.5, and will work in PHP7.0.0? I've got a feeling this might work :- $result= preg_replace("/\[^a-zA-Z0-9]/"," ",$result);but feel I might have over-simplified it, and it maybe doesn't quite do the same thing? Any help much appreciated!
  15. Thanks very much for everyone's input. I think I've got what I need with this: - <?php $targetsection=144; $fullSectionsArray = array(1,1505,1507,1509,1510,1511); $editedSectionsArray = array(); $invertedSectionsArray = array(); $pathsArray = array(); foreach ($fullSectionsArray as &$theSection) { $thispath = get_my_path($theSection); $pathsArray[$theSection] = $thispath; } foreach( $pathsArray as $mKey => &$mVal ) { if( in_array($targetsection, $mVal ) ) { $editedSectionsArray[] = $mKey; } else { $invertedSectionsArray[] = $mKey; } } // $node is the name of the node we want the path of function get_my_path($node) { global $tableSections; // look up the parent of this node $query = "SELECT parent FROM $tableSections WHERE sectionID = " . $node; $result = mysql_query($query); $record = mysql_fetch_assoc($result); // save the path in this array $myPath = array(); // only continue if this $node isn't the root node (that's the node with no parent) if ($record['parent'] != '' && $record['parent'] != '0' && $record['parent'] != '1') { // the last part of the path to $node, is the name // of the parent of $node $myPath[] = $record['parent']; // we should add the path to the parent of this node to the path $myPath = array_merge(get_my_path($record['parent']), $myPath); } // return the result return $myPath; } ?> vinny42 - while I don't doubt your code works and is perhaps the better approach, I start with an array in, and need two arrays out the other end (the template system of the 3rd party application in use expects arrays) and, although I said earlier I don't care about the intermediate path nodes, at some point I might like to list the full paths of all filtered descendants rather than just the immediate parent sections and so the get_my_path function is handy for this. Barand - yours looks a lot more like what I was expecting. I haven't tested it but don't see why it wouldn't work. I may well end up switching to this if I decide I really don't care about full paths! Again, thanks to all for their input
  16. Thanks, but that's as far from simple as it's possible to get (for me, at least!). None of that looks remotely familiar to me, and so I'd rather not use it in case something goes wrong in future. Also, I tried dropping it in on my test server and got 500 errors / blank pages and can't really debug it myself (see previous sentence!). Sorry, I really do appreciate your help, but I think I'd rather a "simple" solution I can drop in to #21
  17. I posted all the code (at that time, - db stuff) in post #20? But since then I've changed my approach a little and feel I'm much closer to a solution (see above).
  18. Ok, that didn't work for a number of reasons....while it seemed to on my test server, it was obviously much more tolerant of my rubbish code as the production server spat it out for numerous reasons, primarily the wrong number of arguments passed to the function in one instance, and the function didn't return an array as expected (I forgot I changed that to true / false). The biggest issue was that the hierarchy seemed to fail after only going 2 generations up....? Anyway, I decided to approach it slightly differently and go back to the function returning a path, then I'll compare the arrays and do what needs doing there...trouble is I've now hit a brick wall as multi-dimensional arrays aren't really a strong point of mine.... What I have: - <?php $targetsection=144; $fullSectionsArray = array(1,1505,1507,1509,1510,1511); $editedSectionsArray = array(); $invertedSectionsArray = array(); $pathsArray = array(); foreach ($fullSectionsArray as &$theSection) { $thispath = get_my_path($theSection); $pathsArray[$theSection] = $thispath; } print_r($pathsArray); /////////////////////////////////////////// // what to do here to populate the other // // 2 arrays - $editedSectionsArray and // // $invertedSectionsArray ??? // /////////////////////////////////////////// echo '<strong>Full Array:</strong><br/>'; echo '<pre>'; print_r($fullSectionsArray); echo '</pre>'; echo '<strong>Edited Array:</strong><br/>'; echo '<pre>'; print_r($editedSectionsArray); echo '</pre>'; echo '<strong>Inverted Array:</strong><br/>'; echo '<pre>'; print_r($invertedSectionsArray); echo '</pre>'; // $node is the name of the node we want the path of function get_my_path($node) { global $tableSections; // look up the parent of this node $query = "SELECT parent FROM $tableSections WHERE sectionID = " . $node; $result = mysql_query($query); $record = mysql_fetch_assoc($result); // save the path in this array $myPath = array(); // only continue if this $node isn't the root node (that's the node with no parent) if ($record['parent'] != '' && $record['parent'] != '0' && $record['parent'] != '1') { // the last part of the path to $node, is the name // of the parent of $node $myPath[] = $record['parent']; // we should add the path to the parent of this node to the path $myPath = array_merge(get_my_path($record['parent']), $myPath); } // return the result return $myPath; } ?> which produces a $pathsArray like: - Array ( [1] => Array ( ) [1505] => Array ( [0] => 1586 [1] => 28 [2] => 222 [3] => 406 ) [1507] => Array ( [0] => 1586 [1] => 28 [2] => 222 [3] => 406 ) [1509] => Array ( [0] => 28 [1] => 222 [2] => 406 ) [1510] => Array ( [0] => 1586 [1] => 28 [2] => 222 [3] => 406 ) [1511] => Array ( [0] => 1586 [1] => 28 [2] => 222 [3] => 406 ) ) All I need to do now (!) is: - add to the $editedSectionsArray, any of $pathsArray in which any value in the sub-array (if there is one) = the $targetsection (e.g. 1505, 1507, 1510 & 1511 in the above example) - taking these key numbers and adding them as values to $editedSectionsArray. add to the $invertedSectionsArray any $pathsArray which either have no sub-arrays, or where the sub-array does not contain $targetsection (e.g. 1 & 1509 in the above example) - taking the key numers and adding them as values to $invertedSectionsArray. Any pointers would be, as always, greatly appreciated.
  19. For the record, I wasn't expecting anyone to do this for me...as I said a nod in the right direction is all I wanted as I didn't want to waste time going down the wrong route. Thanks to all for their input, here's what I have which seems to work Any comments welcome... <?php $targetsection=144; $editedSectionsArray = array(); $invertedSectionsArray = array(); $fullSectionsArray = array(2,3,5,8,13,21,34,55,89); foreach ($fullSectionsArray as &$theSection) { if(get_my_path($theSection,$targetsection)==true && $theSection != $targetsection) { // target section features nowhere in ancestry array_push($invertedSectionsArray,$theSection); } else { // it is there, so add to this array instead array_push($editedSectionsArray,$theSection); } } echo '<strong>Full Array:</strong><br/>'; echo '<pre>'; print_r($fullSectionsArray); echo '</pre>'; echo '<strong>Edited Array:</strong><br/>'; echo '<pre>'; print_r($editedSectionsArray); echo '</pre>'; echo '<strong>Inverted Array:</strong><br/>'; echo '<pre>'; print_r($invertedSectionsArray); echo '</pre>'; // $node is the name of the node we want the path of function get_my_path($node,$targetsection) { global $tableSections; // look up the parent of this node $query = "SELECT parent FROM $tableSections WHERE sectionID = " . $node; $result = mysql_query($query); $record = mysql_fetch_assoc($result); // save the path in this array $myPath = array(); array_push($myPath,$node); // only continue if this $node isn't the root node (that's the node with no parent) if ($record['parent'] != '' && $record['parent'] != '0') { // the last part of the path to $node, is the name // of the parent of $node myPath[] = $record['parent']; if ($record['parent'] == $targetsection) $excludeThis = 1; // we should add the path to the parent of this node to the path $myPath = array_merge(get_my_path($record['parent']), $myPath); } // return the result if (isset($excludeThis)) { return false; } else { return true; } } ?>
  20. Do you mean storing this descendants array somewhere and comparing it whenever I need to? The heirarchy is dynamic and subject to change, quite how often I'm not sure, and so the comparison really needs to be done at that moment...or did you mean something else?
  21. But how do I find all descendants of section 144 without querying every single section and working my way up the hierarchy?
  22. Maybe I've misunderstood, but I'm not sure this is simpler? A section row only lists its parent, not any children. So the only way to find the children of any section is to query the whole sections table for results where it is given as the parent. So, it seems to me, that it's just as difficult to go down the tree as up...?
  23. I was basically looking for a nod in the right direction before starting, as I want to be sure I'm doing it the most efficient way possible with what i've got. The sitepoint article Ch0cu3r linked to looks like a good starting point, I'll post back with actual code if I get stuck (or think what I end up with could be improved upon)...
  24. Thanks I had actually just found that second one before you replied...it looks like it could be a good starting point. I'm stuck with the database structure as it's an existing (third party) application and I'm querying the database, but I should be able to do something based on that...
  25. Not really, I don't care much for the in-between stages. I only need to know which ID's from a given bunch feature the given single ID (in my example 144) anywhere higher up the hierarchy, and those in which 144 doesn't feature.
×
×
  • 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.