Row Reordering

Row Reordering

menashemenashe Posts: 178Questions: 42Answers: 2

I have implemented row reordering, using your great blog example Row reordering.

Specifically, to get the next value, I have modified the pertinent line to:

$next = $discount->db()->sql('select coalesce(MAX(crosswalk_prices_or_purchases_to_discounts.apply_order)+1, 1) as next FROM crosswalk_prices_or_purchases_to_discounts')->fetch();

(In a nutshell, my app allows one or more discount records--which are reorderable--per price record, which is identified by price_id.)

I am just getting over the flu and still not at my best!

Therefore, how would I modify the statement above beginning with '$next = ...' to account for the price_id?

(I believe I need to add the equivalent of "WHERE price_id = $values['crosswalk_prices_or_purchases_to_discounts']['price_id']")

How can I do that?

Answers

  • menashemenashe Posts: 178Questions: 42Answers: 2

    Wow! I guess that it's not as bad as I thought:

                $next = $discount->db()->sql('select coalesce(MAX(crosswalk_prices_or_purchases_to_discounts.apply_order)+1, 1) as next FROM crosswalk_prices_or_purchases_to_discounts WHERE crosswalk_prices_or_purchases_to_discounts.sale_id = ' . $values['crosswalk_prices_or_purchases_to_discounts']['sale_id'])->fetch();
    
  • allanallan Posts: 62,522Questions: 1Answers: 10,272 Site admin

    Nice one. You might want to use a binding if that data is submitted from the client-side though, to make sure you don't have an SQL injection issue. There is some detail on that here.

    Allan

Sign In or Register to comment.