Question: Little Hint To Sql Query

Little Hint To Sql Query

Hi, i need a little hint please! in code i can find for example: ```php $this->datatables ->select('image, code, name, wp.quantity, alert_quantity')

S

Ste

Asked

Hi, i need a little hint please!

in code i can find for example:

 $this->datatables
                    ->select('image, code, name, wp.quantity, alert_quantity')
                    ->from('products')
                    ->join("( SELECT * from {$this->db->dbprefix('warehouses_products')} WHERE warehouse_id = {$warehouse_id}) wp", 'products.id=wp.product_id', 'left')
                    ->where('alert_quantity > wp.quantity', NULL)
                    ->or_where('wp.quantity', NULL)
                    ->where('track_quantity', 1)
                    ->group_by('products.id');
echo $this->datatables->generate();

If i’d like to use a full query like for example:

  $this->datatables
                    ->query("SELECT a.* FROM ... ORDER BY ...");
echo $this->datatables->generate();

But i think i use a wrong syntax… Can you help my with a hint? or what kind of framework i have to check?

Thank you in advance

  • S

    Ste

    Answered

    Mian Saleem Maybe the problem is the column order… from Chrome dev panel:

    in default (working):

    0: “no_image.png” 1: “XXXXX” 2: “XXXXXn” 3: “676.0000” 4: “1000.0000”

    In the custom (not working):

    alert_quantity: “1000.0000” code: “XXXXX” image: “no_image.png” name: “XXXXXn” quantity: “676.0000”

    How to solve? I tried inserting in sColumns but seems not working to order… thank you so much!

  • S

    Ste

    Answered

    in default (working): {“no_image.png”, “XXXXX”, “XXXXXn”, “676.0000”, “1000.0000”}

    In the custom (not working): {image: “no_image.png”, code: “XXXXX”, name: “XXXXXn”, quantity: “676.0000”, alert_quantity:“1000.0000”}

    other differences…

  • EG

    Enyinnaya Gift

    Answered

    Ste Try the example that I gave you, it should be working.

  • MS

    Mian Saleem

    Answered

    Hello,

    There is method result_array() to get array results of query.

    If the column issue you need to check the sColumns and match it with your data.

    Thank you

  • S

    Ste

    Answered

    Enyinnaya Gift Thank you! I tried it but there is some error in the code… i have error 500 on calling…

  • S

    Ste

    Answered

    Mian Saleem I tried with result_array() instead of result() but i have the same result in array:

    in default (working): {“no_image.png”, “XXXXX”, “XXXXXn”, “676.0000”, “1000.0000”}

    In the custom (not working): {image: “no_image.png”, code: “XXXXX”, name: “XXXXXn”, quantity: “676.0000”, alert_quantity:“1000.0000”}

    Thank you! Very very thankfull for your great help!

  • EG

    Enyinnaya Gift

    Answered

    Ste Would you mind if I take a look it on your PC?

    You can reach me via Skype ID: enyinnayag

  • S

    Ste

    Answered

    Enyinnaya Gift THANK YOU so much… my fault! it works!

    thank you again to all of you! Great!

  • S

    Ste

    Answered

    Last hint… the alert quantity on the top bar… where is the file with script to edit? thank you again!

  • EG

    Enyinnaya Gift

    Answered

    Ste Nice.

    Could you please state exactly what worked for you, so that it serves as a reference for others?

  • Login to Reply