Sortable List (with HTML5 Drag'n'Drop API) change the Values in DB

89 Views Asked by At

i'm stuck at the moment with my project. i have to make an sortable list. I used the HTML5 Drag'n'Drop API for that.

When i choose category of our categories in the shop i get some Articles, u can add some Articles and remove them. This is working fine. Now we want to make it sortable ( choose which article is showed first in the list)

the query for taking the article numbers :

 SELECT oxcategories.OXTITLE,
                oxactions.OXCATID, 
                oxactions2article.OXARTID, 
                oxactions2article.OXSORT
            FROM oxcategories 
            LEFT JOIN oxactions ON oxactions.OXCATID = oxcategories.OXID
            INNER JOIN oxactions2article ON oxactions2article.OXACTIONID = oxactions.OXID
            WHERE  oxactions.OXTYPE = -4 AND oxcategories.OXPARENTID LIKE 'oxrootid' AND oxcategories.STCATTYPE = 'w' AND oxcategories.OXACTIVE = 1
            ORDER BY `oxactions2article`.`OXSORT` ASC

I made an sortable list in the template , and u have the possibility to change the order of the Articles that's also working fine.

the function to show the articles:

public function showresult()
    {
        $search = $this->getSelectedValue();
        $bsktArray = $this->getBasketArray();
        $resultArr = array($bsktArray[$search]);
        $sortID = 1;
        if(isset($search))
        {
            echo "Folgende Sku's befinden sich in der Kategorie: <b>".$search."</b><br/><br/>";

            echo "<ul class=\"columns\" style=\"text-align: left;margin-left: -30px;\">";
            foreach ($resultArr as $arr => $val)
            {
                foreach ($val as $sort)
                {
                    foreach ($sort as $sku)
                    {
                        echo " <li class='column' id=$sortID draggable=\"true\">$sku is on  Position $sortID</li>";
                        $sortID++;
                        $array[] = $resultArr;
                    }
                }
            }
        }else{
            echo 'Keine Kategorie gewählt';
        }
        echo" </ul>";
    }

my question now is , How can i save the changed sorting order? I have to change the

oxactions2article.OXSORT

in the Database, but i don't know how i could do that. I'm thankful for any advice.

My Sortable List

0

There are 0 best solutions below