Jump to content
Larry Ullman's Book Forums

bbuster79

Members
  • Posts

    11
  • Joined

  • Last visited

bbuster79's Achievements

Newbie

Newbie (1/14)

2

Reputation

  1. Thanks for your suggestions. I'll continue to tinker with the code. For now I'm manually deleting the entries and then rerunning the script so that only the new jobs are present in the db. Not at all very efficient since the company I hired to write the script left it full of other quirks that require additional manual db administration with every reload. But thank you again for the very educational suggestions. They'll be helpful in not just this project but others soon to come.
  2. Thank you for the very informative reply HartleySan. I've tried the array push, though when I test the contents of the array with print_r() I'm returned a string without any real content in the format of: Array ( [0] => DOMNodeList Object ( ) [1] => DOMNodeList Object ( ) Though when I echo $externalJobAdId before it's pushed into the array, I get the proper id. Any thoughts? Thanks again for your initial reply.
  3. I've updated the script. Instead of creating two arrays, I created only one for the new jobs contained in the daily feed then I used the mysql "NOT IN" function to compare the old jobs with the new ones and delete any jobs that were outdated. It saved me about 9 lines of code and moved some of the workload into the database which is also a good thing. Trouble is now I'm getting a "Cannot use [] for reading" error whenever I run the script. I don't know how else to populate my jobs array. Below is the new code. Sorry if this isn't the most appropriate forum to place this in. Perhaps it would've been better placed in the Advanced PHP 5 forum. <?php $doc = new DOMDocument(); //create a new domdocument to sort through xml tree $doc->load( '/path/daily_jobs.xml' ); //load the daily job feed $jobAds = $doc->getElementsByTagName( "jobAd" ); //create a new instance for every incurrance of a jobAd $newJobs = array(); //create array to hold id's of the new jobs foreach( $jobAds as $jobAd ) { //loop through each job in feed $externalJobAdIds=$jobAd->getElementsByTagName( "externalJobAdId" ); //capture externalJobAdId nodes and set them to a variable to be used as unique identifier $externalJobAdIds = $newJobs[]; //push id's into array } $implodedJobs = implode(",",$newJobs); $query = "DELETE FROM `jobs` WHERE `company_id`= 8060 AND `externalJobAdId` NOT IN($implodedJobs)"; ?>
  4. I have an XML parsing script that's operating a bit quirky. It parses a daily xml feed containing jobs to be featured on my career board. The most urgent problem I need fixed is that old jobs are not dropping off. If a job in my db is not present in the new feed it needs to be deactivated. Here is my preliminary code I was hoping to get some outside thoughts on. -Thanks $doc = new DOMDocument(); //create a new domdocument to sort through xml tree $doc->load( '/path/daily_jobs.xml' ); //load the daily job feed $jobAds = $doc->getElementsByTagName( "jobAd" ); //create a new instance for every incurrance of a jobAd foreach( $jobAds as $jobAd ) { //loop through each job in feed $externalJobAdIds=$jobAd->getElementsByTagName( "externalJobAdId" ); //capture externalJobAdId nodes and set them to a variable to be used as unique identifier $newJobs = array(); //create array to hold id's of the new jobs $externalJobAdIds = $newJobs[]; //push id's into array $query = "SELECT externalJobAdId FROM jobs WHERE company_id = 8060"; //run query to capture job id's already present in db $oldJobs = mysql_query($query); //store results foreach($oldJobs as $job) {//loop through results if(!in_array($newJobs)) { //check if old jobs are still present in today's feed $query = "DELETE * FROM jobs WHERE externalJobAdId = '" . $job . "'"; //delete job if it is not in today's feed mysql_query($query); } } }
  5. I'm querying SELECT * FROM 'companies' WHERE `company_name` = `somecompanyname` But I keep getting an error message saying "Unknown column in where clause" I'm not sure why I'm reaching an error with such a simple query. I'm using PHP 5.2.5 and MyAdmin version 3.3.9.2
  6. Thanks again for all the info. I owe you a lot more than just the price of your books. I've been learning a ton thanks to your guidance.
  7. Thanks again for the info. I appreciate you coming so far off topic from the book to answer these questions. Just one last question if you don't mind. Would the difference in storage methods (cookie vs registered user ID) be your only motivation for separating the wishlist and cart tables each off into 2 separate tables for guests and registered users? BTW, really looking forward to your upcoming Javascript book!
  8. I had the same question myself. An SSL certificate is required to take advantage of HTTPS protocol. If you don't want to buy the certificate you'll need to modify your scripts. What you'll first need to do is comment out lines 10 and 11 from your .htcaccess file. These lines rewrite the admin, checkout and billing URLs to HTTPS. In your checkout.php script, after validation is ran and your sessions are created, you need to change your code: $location = 'https://'.BASE_URL.'billing.php'; header("Location:$location"); exit(); Change the HTTPS to HTTP. You'll also need to make this change to the redirects in billing.php
  9. No, I think you have answered my questions (and raised some new ones). Keeping the user_session_id would make things a lot simpler. I guess though I was thinking in terms of creating a more permanent shopping cart for registered users, so that their items don't expire if they clear their cache or don't log in for 30 days. For this purpose wouldn't I still need to alter the stored procedures a bit, perhaps in the instance of adding products: DELIMITER $$ CREATE PROCEDURE add_to_cart(uid MEDIUMINT, rid MEDIUMINT NULL, type VARCHAR(6), pid MEDIUMINT, qty TINYINT) BEGIN DECLARE cid INT; SELECT id INTO cid FROM carts WHERE user_session_id=uid OR registered_user_id=rid AND product_type=type AND product_id=pid; IF cid > 0 THEN UPDATE carts SET quantity=quantity+qty, date_modified=NOW() WHERE id=cid; ELSE INSERT INTO carts (user_session_id, product_type, product_id, quantity) VALUES (uid, type, pid, qty); END IF; END$$ DELIMITER; As for bridging the HTTP/HTTPS gap I'm not clear on how there would be new difficulties. The checkout.php script GETS the cart_id where it creates the new HTTPS session. Don't we have access to all the info we need at this point?
  10. I've just finished Effortless E-commerce. I really enjoyed the entire book. I particularly like how advanced the database queries got. After reading Quickpro PHP 5 and MYSQL 6 and Quickpro Advanced PHP 5 I'm impressed how much new and fresh content was covered in Effortles E-com. I'm curious now, how labor intensive it would be to add a registration/login function to the coffee site. I'm guessing the DB structure wouldn't require many changes, only a "pass" field in the Customers table and a "customer_id" field added to the Carts and Wishlist tables to use as an alternative to "user_session_id" (or maybe remove user_session_id altogether and reference "customer_id" the way the Orders table does). What I find most daunting though would be trying to alter the stored procedures. I believe everywhere the user_id_session is referenced would have to be changed: add_to_cart, remove_from_cart, update_cart, get_shopping_cart_contents, clear_cart, order_contents, and add_order. I'm also guessing you would have to run an IFELSE check in cart.php, wishlist.php,checkout.php, billing.php scripts to prevent any conflicts or duplicate records when a logged in user is also generated a user_session_id and updates his account. From what I gather though, it doesn't appear there would need be any alterations to the admin scripts or prepared statements. From a usership standpoint, you'd probably want to give a shopper who is not logged in the option to log in, continue as guest or register before adding an item to his cart. In this case you would have to create a $_SESSION['sku'] variable to carry through login or registration so the shopper does not lose his chosen item. Would this work order sound about right?
×
×
  • Create New...