i got a perl script. its over 800 lines.. i dont want to post the whole as most it is not relevant.. the script loops through different data files and input data into a mysql table.

the update when price/stock conditions code , doesn't work as intended as it doesnt take into considertion when the last time data was updated.

I never wrote the script but took a while to figure why it doesnt work.

the prodcut table in dabatse has a field called products_last_modified where date is stored in this format 2015-05-20 03:52:13 .

I need the script to update price/ stock if the products_last_modified data stamp is less then 12 hours.

i am note sure how best to do this.

The code is as

my $product_id; my $sth = $dbh->prepare("SELECT products_id, products_quantity, +products_weight, products_price, vendors_id FROM products WHERE produ +cts.products_model = ".$dbh->quote($data->{'manufacturer_model'})); $sth->execute(); if (my $ref = $sth->fetchrow_hashref()) { $product_id = $ref->{'products_id'}; my $product_price = $ref->{'products_price'}; my $product_quantity = $ref->{'products_quantity'}; my $product_weight = $ref->{'products_weight'}; my $sths = $dbh->prepare("SELECT products_id FROM specials WHE +RE specials.products_id = ".$product_id); $sths->execute(); # don't update if product is in specials unless (my $id = ($sths->fetchrow_array)[0]) { if ($ref->{'vendors_id'} == 1) { $dbh->do("UPDATE products SET products.vendors_id = ".$dat +a->{'vendor_id'}." WHERE products.products_id = ".$product_id); } # update when price/stock conditions met if (($data->{'price'} <= $product_price && $data->{'quantity +'} > 0). || ($product_quantity == 0 && $data->{'quantity'} > 0)) { $dbh->do("UPDATE products SET products.products_price = ".$data->{'price'}.", prod +ucts.products_quantity = ".$data->{'quantity'}.", products.vendors_id = ".$data->{'vendor_id'}.", products +.products_availability = ".$data->{'availability'}." WHERE products.products_id = ".$product_id); } }

In reply to need help with comparing time.. by nasaa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.