Warning: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in C:\\Users\\Public\\Desktop\\Server\\www\\web\\system_files\\sql_class\\_customer_purchase_history.class.php on line 34
Although the syntax looks correct. Could someone else lend a pair of eyes please?
function get_prod_from_sql($New_ship = '', $columnSort = 'item_desc', $viewSort = 'ASC')
{
global $cust_account, $shipping_session, $shipping_id;
$conn = odbc_connect(PROPHET_DATA_SOURCE, PROPHET_USER, PROPHET_PASSW);
if($shipping_session > 0 || $New_ship > 0 )
{
$prod_query = "SELECT * FROM jbi_web_cust_purch_hist
WHERE customer_id = '" .(int)$cust_account. "'
AND ship_to_id = '" .$shipping_session. "'
ORDER BY '".$columnSort."' '".$viewSort."'";
}
else
{
if ($New_ship == "Show_all")
{
$prod_query = "SELECT * FROM jbi_web_cust_purch_hist
WHERE customer_id = '" .(int)$cust_account. "'
ORDER BY '".$columnSort."' '".$viewSort."'";
}
else
{
$prod_query = "SELECT * FROM jbi_web_cust_purch_hist
WHERE customer_id ='" .(int)$cust_account. "'
AND ship_to_id ='".$shipping_id."'
ORDER BY '".$columnSort."' '".$viewSort."'";
}
}
$prod_conn = odbc_exec($conn, $prod_query);
while($favorites = odbc_fetch_array($prod_conn))
{
$part_number = $favorites['part_no'];
$qty = (int)$favorites['qty_shipped'];
$item_desc = $favorites['item_desc'];
$ext_price = $favorites['ext_price'];
$get_prod = db_query("SELECT products_id, short_code FROM " . TABLE_PRODUCTS . " WHERE part_number = '" . $part_number . "'");
$prod_res = db_fetch_array($get_prod);
$this->contents[$favorites['part_no']] = array('qty' => $qty, 'products_id' => $prod_res['products_id'], 'prod_name' => $prod_res['short_code'], 'ext_price' => $ext_price, 'products_name' =>$item_desc);//adding element to the array contents
}
}
The reason I had quotes was because my IDE highlights that area and it’s easier for me to read
Anyway, I tried the die function and this is what it outputs:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'ASC'., SQL state 37000 in SQLExecDirect in C:\\Users\\Public\\Desktop\\Server\\www\\web\\system_files\\sql_class\\_customer_purchase_history.class.php on line 36
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'ASC'.
Although, ASC is a proper SQL syntax, I don’t know why it’s showing that.
I’m noticing when I use ASC or DESC that some the rows are not being put where they are suppose to be.
For example, if I say ORDER BY qty_shipped DESC then it will sort some of the rows in descending order and the rest will be put random order. It’s suppose to show from 1 all the way up into the 4000s.
I’m wondering what’s going on there? How can I fix that? The code is the same as above.
I can’t really check the data type as I don’t have direct access to it. The network admin will not allow a peek into the DB. All I have are the column names :-\
I am noticing though that the Description column works perfect. It will arrange them A-Z or Z-A, but when it comes to numeric it screws all up.
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'jbi_web_cust_purch_hist'., SQL state 37000 in SQLExecDirect in C:\\Users\\Public
Warning: odbc_fetch_array(): supplied argument is not a valid ODBC result resource in C:\\Users\\Public\\Desktop\\Server\\www\\web\\system_files\\sql_class\\_customer_purchase_history.class.php on line 38
$queryTest = "SELECT qty_shipped FROM jbi_web_cust_purch_hist LIMIT 1";
$exec = odbc_exec($conn, $queryTest);
while ($row = odbc_fetch_array($queryTest))
{
var_dump($row['qty_shipped']);
}
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '1'., SQL state 37000 in SQLExecDirect in C:\\Users\\Public\\Desktop\\Server\\www\\web\\system_files\\sql_class\\_customer_purchase_history.class.php on line 39
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '1'.