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 21 to 40 of 48
22 Aug 2014, 1:21 AM
#21
mc12345678 avatar

mc12345678

Totally Zenned

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

Table query is not working. Need some help please.

You have "unbalanced" quotes in this section:

"SELECT * FROM " . TABLE_ORDERS .
where shipping_module_code like "Flat" and orders_status like "3"

The double quotes around flat and 3 need to be single quotes. Otherwise, well basically it breaks. And you need a double quote after the period that follows TABLE_ORDERS. There maybe other issues, but those are the most glaring.

22 Aug 2014, 11:31 AM
#22
lat9 avatar

lat9

Administrator

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

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

mc12345678:

You have "unbalanced" quotes in this section:

"SELECT * FROM " . TABLE_ORDERS .
where shipping_module_code like "Flat" and orders_status like "3"

The double quotes around flat and 3 need to be single quotes. Otherwise, well basically it breaks. And you need a double quote after the period that follows TABLE_ORDERS. There maybe other issues, but those are the most glaring.
Exactly, try this:

$result = $db->Execute ("SELECT * FROM" . TABLE_ORDERS . " WHERE shipping_module_code LIKE 'Flat' AND orders_status = 3");

The orders_status value is stored in the database as an integer, so a straight comparison works more effectively.

22 Aug 2014, 11:46 AM
#23
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.

lat9:

Exactly, try this:

$result = $db->Execute ("SELECT * FROM" . TABLE_ORDERS . " WHERE shipping_module_code LIKE 'Flat' AND orders_status = 3");

> The orders_status value is stored in the database as an integer, so a straight comparison works more effectively.

Haven't tried the above, but see a missing space after the FROM statement (likely to cause an error as well when FROM and TABLE_ORDERS are "put together")

$result = $db->Execute ("SELECT * FROM " . TABLE_ORDERS . " WHERE shipping_module_code LIKE 'Flat' AND orders_status = 3");

22 Aug 2014, 1:13 PM
#24
lat9 avatar

lat9

Administrator

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

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

mc12345678:

Haven't tried the above, but see a missing space after the FROM statement (likely to cause an error as well when FROM and TABLE_ORDERS are "put together")

$result = $db->Execute ("SELECT * FROM " . TABLE_ORDERS . " WHERE shipping_module_code LIKE 'Flat' AND orders_status = 3");

You're quite right; thanks for the update!
23 Aug 2014, 2:27 PM
#25
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 am so close to this being done! Thank you for your help in walking me through my learning curve. I think my last question hopefully will be this one.

I'm trying to submit my form. I have 5 variables. The status variable I just want it to pass the letters OTD I have tried making it a variable and like I did below. Neither works. I keep getting "Parse error: syntax error, unexpected T_STRING in /home4/w57dsjmm/public_html/order/ducky/dispatch_post.php on line 6" I'm not catching anything in the logs. If you need all 3 php pages involved I can post them. Thank you again

<?php
global $db;
$otd = "otd";
$sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :"OTD":)";

$sql = $db->bindVars($sql, ':$orders->fields['order_id']:', $valueOne, 'integer');
$sql = $db->bindVars($sql, ':$orders->fields['date_purchased']:', $valueTwo, 'time');
$sql = $db->bindVars($sql, ':$result->fields['employee_id']:', $valueThree, 'integer');
$sql = $db->bindVars($sql, ':$difference:', $valueFour, 'time');
$sql = $db->bindVars($sql, ':$difference:', $valuefive, 'varchar');
$result = $db->Execute($sql);
$newRecordId = $db->Insert_ID();
echo 'The new record added was number: ' . $newRecordId;
?>
23 Aug 2014, 4:08 PM
#26
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.

southshorepizza:

I am so close to this being done! Thank you for your help in walking me through my learning curve. I think my last question hopefully will be this one.

I'm trying to submit my form. I have 5 variables. The status variable I just want it to pass the letters OTD I have tried making it a variable and like I did below. Neither works. I keep getting "Parse error: syntax error, unexpected T_STRING in /home4/w57dsjmm/public_html/order/ducky/dispatch_post.php on line 6" I'm not catching anything in the logs. If you need all 3 php pages involved I can post them. Thank you again

<?php global $db; $otd = "otd"; $sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :"OTD":)"; $sql = $db->bindVars($sql, ':$orders->fields['order_id']:', $valueOne, 'integer'); $sql = $db->bindVars($sql, ':$orders->fields['date_purchased']:', $valueTwo, 'time'); $sql = $db->bindVars($sql, ':$result->fields['employee_id']:', $valueThree, 'integer'); $sql = $db->bindVars($sql, ':$difference:', $valueFour, 'time'); $sql = $db->bindVars($sql, ':$difference:', $valuefive, 'varchar'); $result = $db->Execute($sql); $newRecordId = $db->Insert_ID(); echo 'The new record added was number: ' . $newRecordId; ?>

Same problem as before, different line:
Change double quotes around OTD to single quotes.
23 Aug 2014, 5:54 PM
#27
southshorepizza avatar

southshorepizza

Zen Follower

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

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

Changed to single quotes around ```
$sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :'OTD':)";

Parse error: syntax error, unexpected T_STRING in /home4/w57dsjmm/public_html/order/ducky/dispatch_post.php on line 6

I went another route.  I changed dispatch_post.php to read 
<?php echo $orders->fields['order_id']; echo $orders->fields['date_purchased']; echo $result->fields['employee_id']; echo $difference; echo 'OTD'; ?>
Then submitted the form my result was OTD  so it's not picking up my variables in the form.
It's displaying them in the form though.  
Only thing I can think is post all three php files here and hope someone can help me sort it out.

dispatch.php main page that has the form.
<?php /** * @package admin * @copyright Copyright 2003-2013 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version GIT: $Id: Author: DrByte Wed Nov 6 21:04:33 2013 -0500 Modified in v1.5.2 $ */ require('includes/application_top.php'); // unset variable which is sometimes tainted by bad plugins like magneticOne tools if (isset($module)) unset($module); require(DIR_WS_CLASSES . 'currencies.php'); $currencies = new currencies(); if (isset($_GET['oID'])) $_GET['oID'] = (int)$_GET['oID']; include(DIR_WS_CLASSES . 'order.php'); ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <link rel="stylesheet" type="text/css" href="includes/dispatch.css"> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ // load text file when page loads $("#div1").load("https://secure3243.hostgator.com/~w57dsjmm/order/ducky/dispatch2.php");
  // Then reload it every 5 seconds, for ever ...
  setInterval(function(){
    $("#div1").load("https://secure3243.hostgator.com/~w57dsjmm/order/ducky/dispatch2.php");
  }, 5000);
});
</script>
</head> <body onLoad="init()"> <!-- header_eof //--> <!-- body //--> <!-- body_text //--> <p><a href="http://order.southshorepizza.net/ducky">ADMIN</A>        Dispatch Screen</p> <form action="dispatch_post.php" method="post"> <div class="dropdown" valign="center"> <select required name="dropdown"> <option value="Select Driver" selected>Select Driver</option> <?php $result = $db->Execute("SELECT * FROM " . TABLE_EMPLOYEES); while (!$result->EOF) { echo '<option value="' . $result->fields['employee_id'] . '">' . $result->fields['employee_first'] . '</option>'; $result->MoveNext(); } ?> </select> </div> <table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr class="dataTableHeadingRow"> <td class="dataTableHeadingContent" width="10%" align="center"><?php echo "Dispatch"; ?></td> <td class="dataTableHeadingContent" width="20%" align="center"><?php echo TABLE_HEADING_ORDERS_ID; ?></td> <td class="dataTableHeadingContent" width="30%" align="center"><?php echo "Address"; ?></td> <td class="dataTableHeadingContent" width="20%" align="center"><?php echo "Order Age"; ?></td> <td class="dataTableHeadingContent" width="20%" align="center"><?php echo TABLE_HEADING_ORDER_TOTAL; ?></td> </tr> </table> <div id="div1"> </div> <input type="submit"> </form> </div> <!-- body_eof //--> </body> </html> ``` dispatch2.php which shows the orders. ``` <?php /** * @package admin * @copyright Copyright 2003-2013 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version GIT: $Id: Author: DrByte Wed Nov 6 21:04:33 2013 -0500 Modified in v1.5.2 $ */

require('includes/application_top.php');

// unset variable which is sometimes tainted by bad plugins like magneticOne tools
if (isset($module)) unset($module);

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

if (isset($_GET['oID'])) $_GET['oID'] = (int)$_GET['oID'];

include(DIR_WS_CLASSES . 'order.php');

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <link rel="stylesheet" type="text/css" href="includes/dispatch.css"> <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS"> </head> <body onLoad="init()"> <!-- body //--> <table border="0" width="100%" cellspacing="2" cellpadding="2"> <!-- body_text //--> <tr> <?php $new_fields = ", o.delivery_street_address, o.shipping_module_code ";
  $orders_query_raw = "select " . $search_distinct . " o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.shipping_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total" .
                      $new_fields . "
                      from (" . TABLE_ORDERS_STATUS . " s, " .
                      TABLE_ORDERS . " o " .
                      $new_table . ")
                      left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id and ot.class = 'ot_total') " . "
                      where (o.orders_status = s.orders_status_id and s.language_id = '" . (int)$_SESSION['languages_id'] . "' and o.shipping_module_code LIKE 'Flat' AND orders_status <> 3)  " .
                      $search . " order by o.orders_id DESC";

//echo '<BR><BR>I SEE C: ' . $orders_query_raw . '<BR><BR>';

//last edit before $orders_query_raw }

// Split Page
// reset page when page is unknown
if (($_GET['page'] == '' or $_GET['page'] <= 1) and $_GET['oID'] != '') {
$check_page = $db->Execute($orders_query_raw);
$check_count=1;
if ($check_page->RecordCount() > '15') {
while (!$check_page->EOF) {
if ($check_page->fields['orders_id'] == $_GET['oID']) {
break;
}
$check_count++;
$check_page->MoveNext();
}
$_GET['page'] = round((($check_count/'15')+(fmod_round($check_count,'15') !=0 ? .5 : 0)),0);
} else {
$_GET['page'] = 1;
}
}

// $orders_query_numrows = '';
$orders_split = new splitPageResults($_GET['page'], '15', $orders_query_raw, $orders_query_numrows);
$orders = $db->Execute($orders_query_raw);
while (!$orders->EOF) {
if ((!isset($_GET['oID']) || (isset($_GET['oID']) && ($_GET['oID'] == $orders->fields['orders_id']))) && !isset($oInfo)) {
$oInfo = new objectInfo($orders->fields);
}

?>

<div id="div1"> <td class="dataTableContent" width="10%" align="center"><input type="checkbox" name="otd" value="$orders->fields['orders_id']" /></td> <td class="dataTableContent" width="20%" align="center"><?php echo $show_difference . $orders->fields['orders_id']; ?></td> <td class="dataTableContent" width="30%" align="center"><?php echo $orders->fields['delivery_street_address']; ?></td> <td class="dataTableContent" width="20%" align="center"><?php $purchase_time = strtotime ($orders->fields['date_purchased']); $difference = time () - $purchase_time; $difference_in_minutes = ceil ($difference / 60); //-Round up to the next minute echo gmdate("H:i:s", $difference); ?></td> <td class="dataTableContent" width="20%" align="center"><?php echo strip_tags($orders->fields['order_total']); ?></td></div> </tr> <?php $orders->MoveNext(); } ?> <tr> <td class="smallText" valign="top" colspan="2"><?php echo $orders_split->display_count($orders_query_numrows, '15', $_GET['page'], TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></td> <td class="smallText" align="left"><?php echo $orders_split->display_links($orders_query_numrows, '15', MAX_DISPLAY_PAGE_LINKS, $_GET['page'], zen_get_all_get_params(array('page', 'oID', 'action'))); ?></td> </tr> </table> <!-- body_text_eof //--> <!-- body_eof //--> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> ``` and dispatch_post.php with just the echo variables ``` <?php <?php global $db; $otd = "otd"; $sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :'OTD':)";

$sql = $db->bindVars($sql, ':$orders->fields['order_id']:', $valueOne, 'integer');
$sql = $db->bindVars($sql, ':$orders->fields['date_purchased']:', $valueTwo, 'time');
$sql = $db->bindVars($sql, ':$result->fields['employee_id']:', $valueThree, 'integer');
$sql = $db->bindVars($sql, ':$difference:', $valueFour, 'time');
$sql = $db->bindVars($sql, ':$difference:', $valuefive, 'varchar');
$result = $db->Execute($sql);
$newRecordId = $db->Insert_ID();
echo 'The new record added was number: ' . $newRecordId;
?>

30 Aug 2014, 12:56 PM
#28
lat9 avatar

lat9

Administrator

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

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

southshorepizza:

I am so close to this being done! Thank you for your help in walking me through my learning curve. I think my last question hopefully will be this one.

I'm trying to submit my form. I have 5 variables. The status variable I just want it to pass the letters OTD I have tried making it a variable and like I did below. Neither works. I keep getting "Parse error: syntax error, unexpected T_STRING in /home4/w57dsjmm/public_html/order/ducky/dispatch_post.php on line 6" I'm not catching anything in the logs. If you need all 3 php pages involved I can post them. Thank you again

<?php global $db; $otd = "otd"; $sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (:$orders->fields['order_id']:, :$orders->fields['date_purchased']:, :$result->fields['employee_id']:, :$difference:, :"OTD":)"; $sql = $db->bindVars($sql, ':$orders->fields['order_id']:', $valueOne, 'integer'); $sql = $db->bindVars($sql, ':$orders->fields['date_purchased']:', $valueTwo, 'time'); $sql = $db->bindVars($sql, ':$result->fields['employee_id']:', $valueThree, 'integer'); $sql = $db->bindVars($sql, ':$difference:', $valueFour, 'time'); $sql = $db->bindVars($sql, ':$difference:', $valuefive, 'varchar'); $result = $db->Execute($sql); $newRecordId = $db->Insert_ID(); echo 'The new record added was number: ' . $newRecordId; ?>
What are you trying to set where?  At the end of the code's running should a row be added to the "hta" table where order_id = $orders->fields['order_id'], order_time = $orders->fields['date_purchased'], employee_id = $result->fields['employee_id'], otd = $difference and status = 'OTD'?

Where does the variable $difference get computed?  Based on order-related information or via a form's input?
30 Aug 2014, 1:25 PM
#29
southshorepizza avatar

southshorepizza

Zen Follower

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

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

A row should be added in the HTA table if there is not already an entry for the order_id. If there is already a row with that order_id it should update that row. I am trying to save the data of who took which order and how old it was when they took it. As we deliver the orders and don't ship them. I will use this data to create a report showing how much $$ they collected and are responsible for turning in to the business at the end of the day. I can also create additional reports based on times.

the variable $difference is computed in the dispatch2.php form

$purchase_time = strtotime ($orders->fields['date_purchased']);
$difference = time () - $purchase_time;
$difference_in_minutes = ceil ($difference / 60);  //-Round up to the next minute
echo gmdate("H:i:s", $difference);

Thank you for your help!

30 Aug 2014, 1:58 PM
#30
lat9 avatar

lat9

Administrator

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

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

OK, since the information is being pulled from the database and/or computed, I think you can get away without all the bindVars calls:

<?php
global $db;
$otd = "otd";
$sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (" . $orders->fields['order_id'] . ", '" . $orders->fields['date_purchased'] . "', " . $result->fields['employee_id'] . ", " . $difference . ", 'OTD')";

$db->Execute($sql);
$newRecordId = $db->Insert_ID();
echo 'The new record added was number: ' . $newRecordId;
?>
30 Aug 2014, 2:16 PM
#31
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 received Fatal error: Call to a member function Execute() on a non-object in admin/dispatch_post.php on line 6

Also so I can learn this would you mind posting the code if I was going to bind these objects? That way I can have a reference on future items.
Thank you.

31 Aug 2014, 4:44 PM
#32
lat9 avatar

lat9

Administrator

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

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

How are you planning on using the script that you're writing? In order to pull in the Zen Cart initializations (like the $db object), you need to add

require ('includes/application_top.php');
31 Aug 2014, 5:11 PM
#33
southshorepizza avatar

southshorepizza

Zen Follower

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

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

Dooh! I included it on the first 2 files but not on the dispatch_post.php. On page 3 is the whole code except the part you helped me change. I will use this to track who(multiple employees) delivered which order. Then I will create a report that shows how much they were responsible for collecting throughout the day so we can collect the appropriate money. I included times into the table so I can create reports showing how long we are taking as well.

Thank you so much for your help. I made this change and made some progress.

WARNING: An Error occurred, please refresh the page and try again.

[31-Aug-2014 13:09:21] PHP Fatal error: 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , , , 'OTD')' at line 1 :: insert into zen_hta (order_id, order_time, employee_id, otd, status) values (, , , , 'OTD') in /home4/w57dsjmm/public_html/order/includes/classes/db/mysql/query_factory.php on line 120

I change a little

<?php
require ('includes/application_top.php');
?>
<?php
global $db;
$otd = "otd";
$sql = "insert into " . TABLE_HTA . " (order_id, order_time, employee_id, otd, status) values (" . $orders->fields['order_id'] . ", " . $orders->fields['date_purchased'] . ", " . $result->fields['employee_id'] . ", " . $difference . ", 'OTD')";

$db->Execute($sql);
$newRecordId = $db->Insert_ID();
echo 'The new record added was number: ' . $newRecordId;
?>
31 Aug 2014, 5:17 PM
#34
lat9 avatar

lat9

Administrator

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

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

That error message indicates that the variables used for the database insert were not set; how about inserting via "code" tags the entire script?

31 Aug 2014, 5:26 PM
#35
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 will have to do some more studying I guess. I'm just starting to learn and not familiar with that term. I will be by tomorrow though. :) thank you! I need to learn some more I guess.
Could my problem be that I am using dispatch.php to start and finish the form and dispatch2.php to bring most of my variables into the form? Is that not allowed even if it displays all in one page?

31 Aug 2014, 6:16 PM
#36
southshorepizza avatar

southshorepizza

Zen Follower

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

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

Or maybe not because I'm not having any luck with googling code tags. lol

31 Aug 2014, 6:46 PM
#37
lat9 avatar

lat9

Administrator

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

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

Sorry, the code tags (which you'd used before) are accessed via the # button when you're creating a post; you put your code between them so that it displays "properly".

1 Sep 2014, 5:54 PM
#38
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 gone back to the drawing board on this and started over. I am much further along. I have 1 bump in the road. When I select the checkbox. It is not giving all the information for that order I am trying to collect. Instead it gives me the correct order number and then it gives me data from the bottom row of the table for everything else.

Here is what I have so far. All the information is from a standard zen-cart 1.5.0 installed database. Therefore anyone should be able to add these files to your install to see exactly what it is doing. Thank you for your help. I am really starting to understand this much better. The below code I now completely understand all but my problem obviously. Weeks ago I understood only a little of it. Thank you so much to all of you.

Here is the code for dispatch.php

<?php
require ('includes/application_top.php');
?>
<form action="dispatch_post.php" method="post">
  <div class="dropdown" valign="center">
    <select required name="driver">
      <option value="Select Driver" selected>Select Driver</option>
      <option value="1">1</option>
      <option value="2">2</option>
    </select>
<?php
      $result = $db->Execute("select orders_id, shipping_method, date_purchased, order_total, delivery_street_address, shipping_module_code from " . TABLE_ORDERS . " where shipping_module_code LIKE 'Flat' AND orders_status <> 3 order by orders_id DESC LIMIT 10");
      while (!$result->EOF) {
$order_id = $result->fields['orders_id'];
        echo "<table border=\"0\" width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">
  <tr>
    <td class=\"dataTableContent\" width=\"10%\" align=\"center\"><input type=\"checkbox\" name=\"order\" value=\"$order_id\" /></td>
    <td class=\"dataTableContent\" width=\"20%\" align=\"center\">" . $result->fields['orders_id'] . "</td>
    <td class=\"dataTableContent\" width=\"30%\" align=\"center\">" . $result->fields['delivery_street_address'] . "</td>";
 $purchase_time = strtotime ($result->fields['date_purchased']);
 $difference = time () - $purchase_time;
 $difference_in_minutes = ceil ($difference / 60);  //-Round up to the next minute
 echo "<td class=\"dataTableContent\" width=\"20%\" align=\"center\">" . gmdate("H:i:s",$difference) . "</td>";
$date_purchased = $result->fields['date_purchased'];
echo"
<input type=\"hidden\" name=\"purchased\" value=\"$date_purchased\">
<input type=\"hidden\" name=\"time\" value=\"$difference\">
<input type=\"hidden\" name=\"OTD\" value=\"OTD\">
    <td class=\"dataTableContent\" width=\"20%\" align=\"center\">$" . strip_tags($result->fields['order_total']). "</td>
  </tr></table>";
     $result->MoveNext(); 
}
echo "<input type=\"submit\" />"
?>

As you can see my form is all now on one php file and all my values for the order number come before the MoveNext() function so I would think I would be getting data from the same order number. But I'm not. I have limited it to 10 records for testing. If I select the top record row #1, I get the order number for the top record row #1. But then all the other form data such as purchased and time comes from record #10 at the bottom.
I am using the following file as dispatch_post.php to echo my values and see if they are correct before saving them to a table.

<?php
require ('includes/application_top.php');
echo "<br> order id: ";
echo $_POST['order'];
echo "<br> Date Purchased: ";
echo $_POST['purchased'];
echo "<br> Driver: ";
echo $_POST['driver'];
echo "<br> time otd: ";
echo $_POST['time'];
echo "<br> Status: ";
echo $_POST['OTD'];
?>

Once again thank you so much to those of you that are helping this rookie learn how to do this!!

1 Sep 2014, 6:51 PM
#39
lat9 avatar

lat9

Administrator

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

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

First, you should always use the built-in Zen Cart functions, where possible. Your use of a hard-coded <form> HTML tag could be part of the problem, since the (required-for-posted-forms) securityToken value isn't included. You were also missing the closing </form> which makes most browsers "mad" so that they won't actually post the form.

Try this:

<?php
require ('includes/application_top.php');
[B]echo zen_draw_form ('dispatch_form', 'dispatch.php', 'post');[/B]
?>
  <div class="dropdown" valign="center">
    <select required name="driver">
      <option value="Select Driver" selected>Select Driver</option>
      <option value="1">1</option>
      <option value="2">2</option>
    </select>
<?php
      $result = $db->Execute("select orders_id, shipping_method, date_purchased, order_total, delivery_street_address, shipping_module_code from " . TABLE_ORDERS . " where shipping_module_code LIKE 'Flat' AND orders_status <> 3 order by orders_id DESC LIMIT 10");
      while (!$result->EOF) {
$order_id = $result->fields['orders_id'];
        echo "<table border=\"0\" width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">
  <tr>
    <td class=\"dataTableContent\" width=\"10%\" align=\"center\"><input type=\"checkbox\" name=\"order\" value=\"$order_id\" /></td>
    <td class=\"dataTableContent\" width=\"20%\" align=\"center\">" . $result->fields['orders_id'] . "</td>
    <td class=\"dataTableContent\" width=\"30%\" align=\"center\">" . $result->fields['delivery_street_address'] . "</td>";
 $purchase_time = strtotime ($result->fields['date_purchased']);
 $difference = time () - $purchase_time;
 $difference_in_minutes = ceil ($difference / 60);  //-Round up to the next minute
 echo "<td class=\"dataTableContent\" width=\"20%\" align=\"center\">" . gmdate("H:i:s",$difference) . "</td>";
$date_purchased = $result->fields['date_purchased'];
[B]echo zen_draw_hidden_field ('purchased', $date_purchased) . zen_draw_hidden_field ('time', $difference) . zen_draw_hidden_field ('OTD', 'OTD');[/B]
echo "<td class=\"dataTableContent\" width=\"20%\" align=\"center\">$" . strip_tags($result->fields['order_total']). "</td>
  </tr></table>";
     $result->MoveNext(); 
}
[B]echo zen_image_submit ('button_submit.gif', 'Submit') . '</form>';[/B]
?>
1 Sep 2014, 7:55 PM
#40
southshorepizza avatar

southshorepizza

Zen Follower

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

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

First, you should always use the built-in Zen Cart functions, where possible.

Where do I find out how to do this? I have searched zen forum, zen wiki, zen blogs, google, bing, dogpile, etc. I'm not finding this information.

Where did it post the results? How do I make this save to my table now?

I added my echo statements to the bottom to see if that would show me what was in the post. I was given the top row order number, no purchase time, and the age of the bottom row(time).

I then changed echo zen_draw_form ('dispatch_form', 'dispatch.php', 'post') to ```
echo zen_draw_form ('dispatch_form', 'dispatch_post.php', 'post')


Surely there must be something written about these built in functions other than what I am finding in the includes/functions/html_output.php file.