Jump to content
Larry Ullman's Book Forums

benster

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by benster

  1. Ah yes, Thank you Larry!

    It now works!

     

    To clarify for others, my final code is

    $r = mysqli_query($dbc, "SELECT CONCAT('O', ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type='other' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type='other' AND c.user_session_id='$uid' UNION SELECT CONCAT('C', sc.id), c.quantity, gc.category, CONCAT_WS(' - ', s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type='coffee' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type='coffee' AND c.user_session_id='$uid'");
    
  2. Hi,

     

    What is the answer to this thread?

    I have copied and pasted the code exactly (adjusting for the " or ' as above),  

     

    $r = mysqli_query($dbc, "SELECT CONCAT('O', ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type='other' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type='other' AND c.user_session_id='$uid' UNION SELECT CONCAT('C', sc.id), c.quantity, gc.category, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type='coffee' AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type='coffee' AND c.user_session_id='$uid'");
    

     

    (also trying '.$uid.' in the code above)

     

    but getting this error message:

     

     

     

    An error occurred in script 'C:\xampp\htdocs\ecommerce\ex2\html\cart.php' on line 113:
    mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
     
     Array

    (

    [0] => Array

    (

    [function] => my_error_handler

    [args] => Array

    (

    [0] => 2

    [1] => mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

    [2] => C:\xampp\htdocs\ecommerce\ex2\html\cart.php

    [3] => 113

    [4] => Array

    (

    [GLOBALS] => Array

    *RECURSION*

    [_POST] => Array

    (

    )



    [_GET] => Array

    (

    )



    [_COOKIE] => Array

    (

    [sESSION] => 630116313b7de1e3fd32bc6393e9ca2c

    )



    [_FILES] => Array

    (

    )



    [live] =>

    [contact_email] => you@example.com

    [uid] => 630116313b7de1e3fd32bc6393e9ca2c

    [page_title] => Coffee - Your Shopping Cart

    [dbc] => mysqli Object

    (

    [affected_rows] => -1

    [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

    [client_version] => 50008

    [connect_errno] => 0

    [connect_error] =>

    [errno] => 1064

    [error] => 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 '0' at line 1

    [field_count] => 0

    [host_info] => localhost via TCP/IP

    [info] =>

    [insert_id] => 0

    [server_info] => 5.5.16

    [server_version] => 50516

    [sqlstate] => 42000

    [protocol_version] => 10

    [thread_id] => 150

    [warning_count] => 0

    )



    [r] =>

    )



    )



    )



    [1] => Array

    (

    [file] => C:\xampp\htdocs\ecommerce\ex2\html\cart.php

    [line] => 113

    [function] => mysqli_num_rows

    [args] => Array

    (

    [0] =>

    )



    )



    )

     
    An error occurred in script 'C:\xampp\htdocs\ecommerce\ex2\html\cart.php' on line 115:
    mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
    Array

    (

    [0] => Array

    (

    [function] => my_error_handler

    [args] => Array

    (

    [0] => 2

    [1] => mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

    [2] => C:\xampp\htdocs\ecommerce\ex2\html\cart.php

    [3] => 115

    [4] => Array

    (

    [GLOBALS] => Array

    *RECURSION*

    [_POST] => Array

    (
    )
    [_GET] => Array
    (
    )
    [_COOKIE] => Array
    (
    [sESSION] => 630116313b7de1e3fd32bc6393e9ca2c
    )
    [_FILES] => Array
    (
    )
    [live] =>
    [contact_email] => you@example.com
    [uid] => 630116313b7de1e3fd32bc6393e9ca2c
    [page_title] => Coffee - Your Shopping Cart
    [dbc] => mysqli Object
    (
    [affected_rows] => -1
    [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $
    [client_version] => 50008
    [connect_errno] => 0
    [connect_error] =>
    [errno] => 1064
    [error] => 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 '0' at line 1
    [field_count] => 0
    [host_info] => localhost via TCP/IP
    [info] =>
    [insert_id] => 0
    [server_info] => 5.5.16
    [server_version] => 50516
    [sqlstate] => 42000
    [protocol_version] => 10
    [thread_id] => 150
    [warning_count] => 0
    )
    [r] =>
    )
    )
    )
    [1] => Array
    (
    [file] => C:\xampp\htdocs\ecommerce\ex2\html\cart.php
    [line] => 115
    [function] => mysqli_num_rows
    [args] => Array
    (
    [0] =>
    )
    )
    )
     

     

     

     


     

    I have echo the $uid and it does print the user_session_id.

     

    If I use the stored procedure, the page works fine.

     

    I have managed to convert the other stored procedures fine.

     

    Any help would be greatly appreciated.

     

    Thanks

     

     

     

    • Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
    • MySQL client version: mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $
×
×
  • Create New...