Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default DB query question

    I would like to query the db with an onclick using JQUERY/AJAX, then return the results without a page refresh. The JQUERY part is not where the problem lies.

    I'm a newb when it comes to PHP. I've been looking over the product info main_template_vars.php file to see if I can figure out how to query the db. I'm not having any luck so far, there is a lot of stuff in there I probably don't need that is throwing me off.

    Here's what I need to happen, user clicks button, button onclick submits Product ID to AJAX script. AJAX script then calls the file product_info_query.php(this would be where the DB query lives). The php file would then query the DB and return results(Product name, Product Image, Product description, product price) for that particular product ID. What's the trick to coding this query into a php file for the zen cart DB?

  2. #2
    Join Date
    May 2010
    Location
    WA State
    Posts
    1,678
    Plugin Contributions
    3

    Default Re: DB query question

    Maybe I'm missing something, but doesn't Zen Cart already do this?

  3. #3
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: DB query question

    No it doesn't, unless I've missed something, I'm building a custom interface that will create itself somewhat dynamically. The only thing left is the DB query. The plan is to return product data without a page refresh so you never leave the page.

  4. #4
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: DB query question

    So you want to have a bunch of buttons that contain only product id info, and load the one product clicked? You can do that, I suppose, but Zen Cart loads all of the product basic info, not just the id, automatically for the product listing page. Unless you have a huge number of them, or they aren't actually defined as to where the button points, you could apply your javascript to showing only the called-for set of already-loaded products.

  5. #5
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: DB query question

    I only have a few products so I created my own index page. Right now it is hard coded, but I want to make it easier to update by making it dynamic. For me the easiest way is via Javascript because I understand it. PHP not so much. I've spent a couple of days analyzing the code. I have done a basic proof of concept with a standard db query:
    Code:
    $db = mysql_select_db(DB) or  die('Could not connect to database !<br />Please contact the site\'s administrator.');
    
    $query = mysql_query(" SELECT * FROM products_description WHERE products_id='".$_POST['value']."' ");
    With a few other bits for formatting it returned basic results. However what I want to do is rework a copy of the main_template_vars.php file used with the product info page so it will execute on a $_POST. This would be easy enough if I could actually figure out how zen cart is querying the DB. It looks as though Zen cart would normally execute this page as it loaded the header for the product info page using the $_GET command with the product ID

    Code:
    $sql = "select count(*) as total
              from " . TABLE_PRODUCTS . " p, " .
                       TABLE_PRODUCTS_DESCRIPTION . " pd
              where    p.products_status = '1'
              and      p.products_id = '" . (int)$_GET['products_id'] . "'
              and      pd.products_id = p.products_id
              and      pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
    
    
      $res = $db->Execute($sql);
    I understand this section for the most part, but where are the $res and $db variable being defined in zen cart, where is the mysql connect, select and query that define those variables? There seem to be multiple files needed the execute upon loading the product info page that I must be missing in order to get this script running. I need to figure out if there is a way to execute it as a stand alone file when the $_GET is replaced by a $POST variable?

  6. #6
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: DB query question

    Apparently your unique requirements are demanding that you write your own custom PHP-based ajax handler.
    The $db object is built by calling application_top.php as part of normal bootstrapping. Anything you do outside of that means you'll need to write your own complete framework instead of using the Zen Cart core code framework which spawns from index.php and application_top. If you skip calling application_top then you also bypass all the security protections and other safeties built into the system.
    There are numerous existing addons which have built their own ajax handlers. You might consider one of those instead of writing your own from the ground up.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: DB query question

    It rather sounds like you want to reinvent the wheel when all you really need is whitewalls and a different tread pattern. I think you will spend a huge amount more time getting your custom page to run completely right than if you tweaked the existing pages.

  8. #8
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: DB query question

    I think you guys have mis-read what I was trying to do. I am not trying to re-invent the wheel. All I am trying to do is make a call to query the DB, that in theory seems like it should be pretty simple. To do that I was attempting to figure out the process in which zen cart does this, but there are so many files that are used to for one page I've been trying to wrap my head around what is what. In the end I want to use the existing function and security of the cart, yet still have a streamlined page.

  9. #9
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: DB query question

    I only have a few products so I created my own index page.
    If you modified the existing product listing page (which is an index page), you would have all of the correct fundamental Zen Cart handling, to which you could just add your desired javascript display functionality. How did you make your custom index page, anyway?

  10. #10
    Join Date
    Jan 2008
    Posts
    67
    Plugin Contributions
    0

    Default Re: DB query question

    I turned off the header, footer and sideboxes in the template files, I turned everything off that displays on the index page, basically giving me a blank canvas. I designed a new index page using the define_main_page.php file. I removed all links to anything I didn't need such as search, notifications, etc. So now I have my index page with my products and other info in a few divs. The add to cart buttons are currently javascript based forms. It works well with the only real issue I have is that when I decide to add new products, or change products, which won't be often, I'll have to add/edit them manually on my define main page file and the backend admin section.

    I like this format better because the customer see's the product, clicks on it and a lightbox window is called which pops up with the description, photo and add to cart button. Some attributes for said product are passed silently, ie. if it includes attributes(like color) that should not be user selectable, along with user selectable attributes(like size), all with one button click, and the customer never leaves the main page. The customer is quickly guided from the add to cart through checkout in only about 4-5 page clicks. If I could combine the checkout process to one page I'd probably do that too, cutting down pages clicks even less.

    Maybe I am trying to reinvent the wheel, I look at it more like turning a whitewall into a low profile, but I needed a basic streamlined cart and zen cart fit the bill for the most part; However my lack of php knowledge made it easier to do everything in javascript on the define_main_page file rather than tweak the php. So here I am, maybe I just leave it as is, or I figure out another way to do it utilizing the product_info.php page somehow.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Rewards Points - Global Query/Point Addition Question
    By Youngblood in forum General Questions
    Replies: 0
    Last Post: 26 Jul 2011, 04:27 PM
  2. Query Question
    By fotofx in forum General Questions
    Replies: 0
    Last Post: 5 Oct 2010, 02:51 AM
  3. Basic query question with MoveNext
    By delia in forum Contribution-Writing Guidelines
    Replies: 2
    Last Post: 12 Jan 2010, 05:20 PM
  4. also purchased query question
    By ryanf in forum General Questions
    Replies: 14
    Last Post: 15 Aug 2009, 07:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg