Zen Cart Logo
Forums / General Questions / Can I read in data from the database?

Can I read in data from the database?

Views: 919

Results 1 to 7 of 7
23 Sep 2013, 9:59 PM
#1
hutintheindies avatar

hutintheindies

New Zenner

Join Date:
May 2011
Posts:
8
Plugin Contributions:
0

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!

24 Sep 2013, 4:27 AM
#2
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Can I 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).

25 Sep 2013, 7:38 PM
#3
hutintheindies avatar

hutintheindies

New Zenner

Join Date:
May 2011
Posts:
8
Plugin Contributions:
0

Re: Can I 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.

25 Sep 2013, 9:12 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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).

26 Sep 2013, 11:08 PM
#5
hutintheindies avatar

hutintheindies

New Zenner

Join Date:
May 2011
Posts:
8
Plugin Contributions:
0

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

$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?

26 Sep 2013, 11:19 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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.

27 Sep 2013, 5:20 PM
#7
hutintheindies avatar

hutintheindies

New Zenner

Join Date:
May 2011
Posts:
8
Plugin Contributions:
0

Re: Can I read in data from the database?

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

$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!!