Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    May 2008
    Location
    United States
    Posts
    490
    Plugin Contributions
    1

    Default How to use MoveNext();

    The below statement works for tracking orders that only have a single tracking number:

    PHP Code:
            $order_number=$_POST['order_number'];
          
    $track_rs $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = '" . (int)$order_number "' LIMIT 1");
          if (
    $track_rs ->RecordCount() > 0) {
            
    $track_num $track_rs ->fields['tracking_number'];
            
    header('Location: http://example dot com/' $track_num);
          } else {
          
    $messageStack->add('tracking'ENTRY_ORDER_NUMBER_ERROR3);
          } 
    So basically above code works as follows:

    Customer enters an order number on our tracking page and if that order number exist then the following is executed:
    header('Location: http://example dot com/' . $track_num);

    This is fine for 99% of orders which only ship in one package however I do ship single order sometimes in multiple packages so I will have to account for this in the above statement somehow.

    So if only one result then do what it is doing now, execute the below :
    header('Location: http://example dot com/' . $track_num);

    if more then 1 entry is in the results then show on a separate page or on the tracking page as results something like:

    This order shipped in xx box's:

    Package 1: Click to Track

    Package 2: Click to Track

    Package 3: Click to Track

    Package 4: Click to Track

    Package 5: Click to Track

    Each "Click to Track" needs to be one of the results so for example the five above would be:


    http://customurl.com/[/url]' . $track_num[Result 1]
    http://customurl.com/[/url]' . $track_num[Result 2]
    http://customurl.com/[/url]' . $track_num[Result 3]
    http://customurl.com/[/url]' . $track_num[Result 4]
    http://customurl.com/[/url]' . $track_num[Result 5]

    I have no clue how to properly write this in code, any help would be most appreciated.
    Last edited by marcopolo; 4 Nov 2015 at 02:41 AM.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: How to use MoveNext();

    Quote Originally Posted by marcopolo View Post
    The below statement works for tracking orders that only have a single tracking number:

    PHP Code:
            $order_number=$_POST['order_number'];
          
    $track_rs $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = '" . (int)$order_number "' LIMIT 1");
          if (
    $track_rs ->RecordCount() > 0) {
            
    $track_num $track_rs ->fields['tracking_number'];
            
    header('Location: http://example dot com/' $track_num);
          } else {
          
    $messageStack->add('tracking'ENTRY_ORDER_NUMBER_ERROR3);
          } 
    So basically above code works as follows:

    Customer enters an order number on our tracking page and if that order number exist then the following is executed:
    header('Location: http://example dot com/' . $track_num);

    This is fine for 99% of orders which only ship in one package however I do ship single order sometimes in multiple packages so I will have to account for this in the above statement somehow.

    So if only one result then do what it is doing now, execute the below :
    header('Location: http://example dot com/' . $track_num);

    if more then 1 entry is in the results then show on a separate page or on the tracking page as results something like:

    This order shipped in xx box's:

    Package 1: Click to Track

    Package 2: Click to Track

    Package 3: Click to Track

    Package 4: Click to Track

    Package 5: Click to Track

    Each "Click to Track" needs to be one of the results so for example the five above would be:


    http://customurl.com/[/url]' . $track_num[Result 1]
    http://customurl.com/[/url]' . $track_num[Result 2]
    http://customurl.com/[/url]' . $track_num[Result 3]
    http://customurl.com/[/url]' . $track_num[Result 4]
    http://customurl.com/[/url]' . $track_num[Result 5]

    I have no clue how to properly write this in code, any help would be most appreciated.
    Code:
    $order_number=$_POST['order_number'];
      $track_rs = $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = " . (int)$order_number);
      if ($track_rs ->RecordCount() == 1) {
        $track_num = $track_rs ->fields['tracking_number'];
    header('Location: http://example dot com/' . $track_num);
      } elseif ($track_rs ->RecordCount() > 0) {
        $track_num = array();
        whiile(!$track_rs->EOF) {
          $track_num[] = $track_rs ->fields['tracking_number'];
          $track_rs->MoveNext();
        }
    echo 'This order shipped in ' . sizeof($track_num). ' box' .(sizeof($track_num) != 1 ? 'es' : '') . ':';
    echo "\n";
    foreach ($track_num as $key => $val) {
      echo 'Package ' . $key . ':  <a href="http://customurl.com/' . $val . '">Click to Track</a>';
      echo "\n";
    }
      
      } else {
          $messageStack->add('tracking', ENTRY_ORDER_NUMBER_ERROR3);
      }
    More untested code... Might be some formatting issues (caps where not expected), but concept should work...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: How to use MoveNext();

    Small typo
    Code:
    whiile(!$track_rs->EOF)
    Should be
    Code:
    while(!$track_rs->EOF)

  4. #4
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Re: How to use MoveNext();

    Some companies will let you use an API which will allow you to display the details in your orders history page which is more complex, but overall a nice feature to have. You will likely need to have an account with the shipping company though.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: How to use MoveNext();

    Design75, thank you for correcting that, especially for those not familiar with PHP "construct" (spelling... )

    Regarding application of this method of shipping info I still think this method of uri rewrite to obtain tracking info off of the web address regardless of who is asking is a less than desirable solution... The request should be posted to the next page which should validate that the request came from a ZC (customer) "user" otherwise, you may find the destination uri to be abused by other "visitors". Further if the input is not properly protected "upon receipt" may be open to other "trouble".
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    May 2008
    Location
    United States
    Posts
    490
    Plugin Contributions
    1

    Default Re: How to use MoveNext();

    mc12345678 worked perfect thank you! You are talented my friend wish I was able to code like that!

    Going to play around with it right now it echos to the top of the page as follows:

    This order shipped in 3 boxes: Package 0: Click to Track Package 1: Click to Track Package 2: Click to Track

    Is there a way to make Package count start at 1 not 0?

    Regarding application of this method of shipping info I still think this method of uri rewrite to obtain tracking info off of the web address regardless of who is asking is a less than desirable solution... The request should be posted to the next page which should validate that the request came from a ZC (customer) "user" otherwise, you may find the destination uri to be abused by other "visitors". Further if the input is not properly protected "upon receipt" may be open to other "trouble".
    The input is protected by Google reCAPTCHA and the following:

    PHP Code:
      if (!empty($order_number) && ctype_digit($order_number) && preg_match('/^[0-9]{8}+$/'$order_number) && $error==false) { 
    So basically only a valid 8 digit order number (which is randomly generated at the time of order) is accepted otherwise nothing happens you receive an error to enter an 8 digit number, is that good?

  7. #7
    Join Date
    May 2008
    Location
    United States
    Posts
    490
    Plugin Contributions
    1

    Default Re: How to use MoveNext();

    Trying to redirect before echoing so I can format the results nicely on a new page, but it's not working. I think the output needs to be put into variables before doing this right?

    PHP Code:
    $order_number=$_POST['order_number'];
      
    $track_rs $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = " . (int)$order_number);
      if (
    $track_rs ->RecordCount() == 1) {
        
    $track_num $track_rs ->fields['tracking_number'];
    header('Location: http://example.com/' $track_num);
      } elseif (
    $track_rs ->RecordCount() > 0) {
        
    $track_num = array();
        while(!
    $track_rs->EOF) {
          
    $track_num[] = $track_rs ->fields['tracking_number'];
          
    $track_rs->MoveNext();
        }
          
    zen_redirect(zen_href_link(FILENAME_TRACKING'action=multiple_packages'));

    echo 
    'This order shipped in ' sizeof($track_num). ' box' .(sizeof($track_num) != 'es' '') . ':';
    echo 
    "\n";
    foreach (
    $track_num as $key => $val) {
      echo 
    'Package ' $key ':  <a href="http://example.com/' $val '">Click to Track</a>';
      echo 
    "\n";
    }
      
      } else {
          
    $messageStack->add('tracking'ENTRY_ORDER_NUMBER_ERROR3);


  8. #8
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: How to use MoveNext();

    Code:
    $order_number=$_POST['order_number'];
      $track_rs = $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = " . (int)$order_number);
      if ($track_rs ->RecordCount() == 1) {
        $track_num = $track_rs ->fields['tracking_number'];
    header('Location: http://example dot com/' . $track_num);
      } elseif ($track_rs ->RecordCount() > 0) {
        $track_num = array();
        while(!$track_rs->EOF) {
          $track_num[] = $track_rs ->fields['tracking_number'];
          $track_rs->MoveNext();
        }
    echo 'This order shipped in ' . sizeof($track_num). ' box' .(sizeof($track_num) != 1 ? 'es' : '') . ':';
    echo "\n";
    foreach ($track_num as $key => $val) {
      echo 'Package ' . ($key+1) . ':  <a href="http://customurl.com/' . $val . '">Click to Track</a>';
      echo "\n";
    }
      
      } else {
          $messageStack->add('tracking', ENTRY_ORDER_NUMBER_ERROR3);
      }
    Above is the code with reconsideration of the fact that arrays in PHP are zero based and the correction identified by design75.

    My concern is that the shipping code (pulled from the database) and assumed (you know how that goes) to be a "standard" shipping identification code of one or more services is being sent to a "receiving" page that can be accessed by anyone using a similar shipping/tracking number. Otherwise an 8 digit number, does it "get deleted" after use? Even still, that's just 10,000,000 possible combinations....
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    May 2008
    Location
    United States
    Posts
    490
    Plugin Contributions
    1

    Default Re: How to use MoveNext();

    My concern is that the shipping code (pulled from the database) and assumed (you know how that goes) to be a "standard" shipping identification code of one or more services is being sent to a "receiving" page that can be accessed by anyone using a similar shipping/tracking number. Otherwise an 8 digit number, does it "get deleted" after use? Even still, that's just 10,000,000 possible combinations....
    The receiving page is a third party service called Aftership and the tracking number that is attached to the end of the url you see in the code will only work if it is in their database, which I have to import them for it to be in their database.

    After 30 days the tracking numbers expire.

  10. #10
    Join Date
    May 2008
    Location
    United States
    Posts
    490
    Plugin Contributions
    1

    Default Re: How to use MoveNext();

    Ok I made the following change to the code which will now redirects the output with multiple results to another page.

    This code is in my header file:

    PHP Code:
    $order_number=$_POST['order_number'];
      
    $track_rs $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = " . (int)$order_number);
      if (
    $track_rs ->RecordCount() == 1) {
        
    $track_num $track_rs ->fields['tracking_number'];
    header('Location: http://customurl.com/' $track_num);
      } elseif (
    $track_rs ->RecordCount() > 0) {
    $_SESSION['order_number'] = $order_number;
          
    zen_redirect(zen_href_link(FILENAME_TRACKING'action=trackingInfo'));
      
      } else {
          
    $messageStack->add('tracking'ENTRY_ORDER_NUMBER_ERROR3);
      } 
    This code is in my templates file:

    PHP Code:
    <?php
      
    if (isset($_GET['action']) && ($_GET['action'] == 'trackingInfo')) {
    ?>
    <div class="mainContent trackingInfo"></div>

    <?php
    $order_number 
    $_SESSION['order_number'];
      
    $track_rs $db->Execute("SELECT tracking_number FROM fulfill_tracking WHERE order_number = " . (int)$order_number);
     if (
    $track_rs ->RecordCount() > 0) {
        
    $track_num = array();
        while(!
    $track_rs->EOF) {
          
    $track_num[] = $track_rs ->fields['tracking_number'];
          
    $track_rs->MoveNext();
    }
    echo 
    '<p class="trackingInfoBoxes">This order shipped in ' sizeof($track_num). ' box' .(sizeof($track_num) != 'es' '') . ':</p>';
    echo 
    "\n";
    foreach (
    $track_num as $key => $val) {
      echo 
    '<p class="trackingInfoPackages">Package ' . ($key+1) . ':  <a href="http://customurl.com/' $val '">Click to Track</a></p>';
      echo 
    "\n";
    }
      }
    ?>
    It works not sure if there is a better way of doing it though. Thanks again for the help!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 14
    Last Post: 12 Apr 2016, 02:47 PM
  2. v139h How to reset an object after using MoveNext()?
    By Cyberkiller in forum General Questions
    Replies: 6
    Last Post: 30 Mar 2012, 05:27 PM
  3. Basic query question with MoveNext
    By delia in forum Contribution-Writing Guidelines
    Replies: 2
    Last Post: 12 Jan 2010, 05:20 PM
  4. How can I use Multiple mods that use same files?
    By sfklaas in forum General Questions
    Replies: 1
    Last Post: 8 May 2009, 10:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg