Zen Cart Logo
Forums / General Questions / Table query is not working. Need some help please.

Table query is not working. Need some help please.

Views: 4,381

Results 41 to 48 of 48
1 Sep 2014, 8:09 PM
#41
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,086
Plugin Contributions:
56

Table query is not working. Need some help please.

Whoops, my bad. The form-creation function should look like:

echo zen_draw_form ('dispatch_form', zen_href_link ('dispatch.php'), 'post')

Where is this stuff documented? There's some documentation at http://phpcrossref.com/xref/zencart/ and http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials.

Mostly, I find something that "looks like" what I'm trying to do and use it as a model.

1 Sep 2014, 8:16 PM
#42
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Table query is not working. Need some help please.

Thank you. I'm off to my part time job. lol I"ll read up when I get a break or after work(midnight). Thank you so much!

30 Sep 2014, 9:25 PM
#43
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Table query is not working. Need some help please.

I have finally had luck thanks to Chu in getting this working correctly. Now I am trying to build a simple report. I have a drop down list of available employees to choose from and then you submit the form.

<?php

/**
 * DISPATCH REPORT 3.1
*/

  require('includes/application_top.php');
  
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $employees_array = array();
  $employees_array[] = array('id' => '', 'text' => 'Select Driver');
  $employees = $db->Execute('SELECT * FROM ' . DB_PREFIX . 'employees');
  while(!$employees->EOF) {
    $employees_array[] = array('id' => $employees->fields['employee_id'], 'text' => $employees->fields['employee_first']);
    //$employees_array[] = array('id' => $employees->fields['employee_id'], 'text' => $employees->fields['employee_first'] . ' ' . $employees->fields['employee_last']);
    $employees->MoveNext();
  }
?>
<?php echo  zen_draw_form('drivercheckoutform', 'drivercheckout', zen_get_all_get_params(array('page', 'action')) . 'page=' . $_GET['page'] . '&action=submit', 'post'); ?>
<div align="center" id="employeebox"><?php echo zen_draw_pull_down_menu('employee_id', $employees_array);?></div>
<div align="right"><button type="submit">Submit</button></div>

The above code has db_prefix and I haven't successfully been able to change that to TABLE_EMPLOYEES. A little help there would be great.

This brings you to drivercheckout.php

On this page I want to query TABLE_HTA and return all rows that have status 'OTD' and the selected employee 'ID' for the current day. Then I will display the order number(order_id) and total(order_total) for each record. At the bottom of the report I want to have a total for all orders appearing in the chart($total) So far I have this:

<?php

  require('includes/application_top.php');
  
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
  
  $start_date = date(DATE_FORMAT, mktime(0, 0, 0, date("m"), date("d"), date("Y")));
  $end_date = date(DATE_FORMAT, mktime(23, 59, 59, date("m"), date("d"), date("Y")));
  
  
$sql = 'SELECT * FROM ' . TABLE_HTA . ' WHERE date >= ' . date("Y-m-d H:i:s", $start_date) . ' AND date < ' . date("Y-m-d H:i:s", $end_date) . ' AND employee_id = ' . $employee_id . ';
              $orders = $db->Execute($sql);
			  $total = 0;
              if($orders->RecordCount() > 0) {
                while(!$orders->EOF) {
				 ?>
                  <tr>
                    <td align="center"><?php echo $orders->fields['order_id'];?></td> 
                    <td align="center"><?php echo $orders->fields['otd_time'];?>
                    <td align="right"><?php echo $currencies->format($orders->fields['order_total']);?></td>
					<?php $total=$total+$orders->fields['order_total'];?>
                  </tr>
                  <?php
                  $orders->MoveNext();
                }?>
				<tr>
				<td></td>
				<td></td>
				<td><?php echo $total;?></td>
				<?php
              }
              ?>

I know my query is wrong. I'm not even positive it is using the employee_id from the submitted form. This will be my first report I create so I'm really just learning this. I have looked at many examples and tried to use as a pattern and this is what I have so far.

Thank you so much for your help in learning this!

21 Nov 2014, 12:08 AM
#44
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Table query is not working. Need some help please.

Having a little trouble getting this to work. Your help is appreciated.

<?php    
    $mysql = 'SELECT o.orders_id, h.status from ' . TABLE_ORDERS . ' o inner join ' . TABLE_HTA . ' h ON o.orders_id = h.order_id WHERE o.orders_id = '.$zv_orders_id.'';
              $orders = $db->Execute($mysql);
			
              if($orders->fields['status'] = OTD) {echo "Your order is being delivered now.";}
			  elseif ($orders->fields['status'] = MADE) {echo "Your order is being cooked.";}
			  else {echo "Your order is being made";} 
			    ?>

When the order is first made it should be echoing "Your order is being made."
Instead it gets stuck on the first if statement and echoes "Your order is being delivered now."

I've tried using 'OTD' AND 'MADE'. I've also tried using "OTD" and "MADE" in the if statements. The select query is working as there are no error logs being generated and it works in the sql of phpmyadmin orders_id 32015 returns orders_id=32015 and status=MADE so I know I'm getting the data.

21 Nov 2014, 12:44 AM
#45
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Table query is not working. Need some help please.

When checking for equality need to use == not = (assignment) which evaluates to true and why the first if is always taken

21 Nov 2014, 12:57 AM
#46
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Table query is not working. Need some help please.

Thank you!

21 Nov 2014, 1:04 AM
#47
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Table query is not working. Need some help please.

Welcome. Fyi, there is also === which would be used to evaluate for example that if the variable holds false but wanted to verify that it was 0 then the answer would be false where 0===false. But when the same values are compared using == they result is true... There is also !== which is the not or reverse of the test in this message. To compare as an opposite in your code could use != for the comparison. 1 != 0 is a true statement and can be used to compare two such values.

21 Nov 2014, 1:20 AM
#48
southshorepizza avatar

southshorepizza

Zen Follower

Join Date:
Sep 2012
Posts:
253
Plugin Contributions:
0

Re: Table query is not working. Need some help please.

Thank you again! Interesting the difference between =, ==, and ===.