Results 1 to 7 of 7
  1. #1
    Join Date
    May 2011
    Posts
    8
    Plugin Contributions
    0

    Default Can I read in data from the database?

    I would like to be able to have the tracking number for each order associated with each record on the account history.
    I have made a column in the order sheet of the database that is entitled "tracking_number" and I have edited the "tpl_account_histroy_info_default.php" and "accout_history_info.php" files and I have been able to create headers and tables and everything I need but i can't seem to figure out how zencart is reading in the values from the database based on the order number.

    I have tried mimicking the php code using phrases such as

    "<div><?php echo $order->info['tracking_number']; ?></div>"
    or
    "<?php echo $order->products[$i]['tracking_number']; ?>"

    and they aren't doing anything. And I don't know enough about php to dare guessing anything else. If anyone can help me out that would be great.

    My website is readyholster.com. I cant really send a link of the page in question as you have to be able to log in to see it.
    Thanks for any help!

  2. #2
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: How to read in data from the database

    Have you checked out Ty Package Tracker? It adds a fair number of features related to shipping tracking numbers (email, adding to an order from the admin, displaying in customer's order history, etc).
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  3. #3
    Join Date
    May 2011
    Posts
    8
    Plugin Contributions
    0

    Default Re: How to read in data from the database

    Sweet that looks great! Though if there is anyone that could help me out with the database call, I really feel like that would be very helpful for future problems without having to find another module.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Can I read in data from the database?

    You've gotta include the field name in the query that pulls the relevant data from the database (usually done in the header_php.php file, or in one of the files it calls, such as the order class), and then you can echo it out in the template (similar to the many other variables echoed there already).
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    May 2011
    Posts
    8
    Plugin Contributions
    0

    Default Re: Can I read in data from the database?

    I found the right header_php.php file and opened it up. I want to put the tracking number in the "Status History & Comments" table so I found the part where it calls those spots in the database which I think is the bit of code shown below and did my best to mimic it to add the tracking number. In bigger font is what I added

    Code:
    $statuses_query = "SELECT os.orders_status_name, osh.date_added, osh.comments, osh.tracking_number
                       FROM   " . TABLE_ORDERS_STATUS . " os, " . TABLE_ORDERS_STATUS_HISTORY . " osh
                       WHERE      osh.orders_id = :ordersID
                       AND        osh.orders_status_id = os.orders_status_id
                       AND        os.language_id = :languagesID
                       AND        osh.customer_notified >= 0
                       ORDER BY   osh.date_added";
    
    $statuses_query = $db->bindVars($statuses_query, ':ordersID', $_GET['order_id'], 'integer');
    $statuses_query = $db->bindVars($statuses_query, ':languagesID', $_SESSION['languages_id'], 'integer');
    $statuses = $db->Execute($statuses_query);
    
    while (!$statuses->EOF) {
    
      $statusArray[] = array('date_added'=>$statuses->fields['date_added'],
      'orders_status_name'=>$statuses->fields['orders_status_name'],
      'comments'=>$statuses->fields['comments'],
      'tracking_number'=>$statuses->fields['tracking_number']);
    
      $statuses->MoveNext();
    }
    However when I update it the page crashes and it gives me the following error message:

    "1054 Unknown column 'osh.tracking_number' in 'field list'
    in:
    [SELECT os.orders_status_name, osh.date_added, osh.comments, osh.tracking_number FROM orders_status os, orders_status_history osh WHERE osh.orders_id = 10943 AND osh.orders_status_id = os.orders_status_id AND os.language_id = 1 AND osh.customer_notified >= 0 ORDER BY osh.date_added]"

    Which is in a way slightly comforting because it makes me feel like I am doing something, yet I am still far from fixing it.
    What am I missing? or Do I have too much? Would it be easier to display the tracking number in a different place so that it would be easier to implement? What does the os. or osh. mean? Is this too many questions for one post?

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Can I read in data from the database?

    FROM " . TABLE_ORDERS_STATUS . " os, " . TABLE_ORDERS_STATUS_HISTORY . " osh
    In the context of the query you quoted,
    os is a shortname/alias for TABLE_ORDERS_STATUS
    osh is an alias for TABLE_ORDERS_STATUS_HISTORY

    Thus, osh.tracking_number would refer to a field named "tracking_number" in the orders_status_history table.

    And your latest error message indicates that no such field exists in that table.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    May 2011
    Posts
    8
    Plugin Contributions
    0

    Default Re: Can I read in data from the database?

    Perfect!! So all I had to do was add another database so I put

    Code:
    $statuses_query = "SELECT os.orders_status_name, osh.date_added, osh.comments, o.tracking_number
                       FROM   " . TABLE_ORDERS_STATUS . " os, " . TABLE_ORDERS_STATUS_HISTORY . " osh, " . TABLE_ORDERS . " o 
                       WHERE      osh.orders_id = :ordersID
                       AND        osh.orders_status_id = os.orders_status_id
    				   AND		  osh.orders_id = o.orders_id
                       AND        os.language_id = :languagesID
                       AND        osh.customer_notified >= 0
                       ORDER BY   osh.date_added";
    And now it works perfectly! Thanks!!

 

 

Similar Threads

  1. Replies: 3
    Last Post: 15 Jul 2013, 08:02 AM
  2. Is this a bug? can barely upload new data to the database
    By Thannaree in forum General Questions
    Replies: 13
    Last Post: 16 Mar 2011, 10:03 AM
  3. Can I export the zen cart database from the admin?
    By jettrue in forum General Questions
    Replies: 2
    Last Post: 13 Apr 2009, 08:11 AM
  4. Can no longer read database
    By tedpottel in forum Installing on a Linux/Unix Server
    Replies: 1
    Last Post: 24 Oct 2008, 11:08 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR