More CMS help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon

    More CMS help

    All,

    I'm building a CMS, and have run into another problem that I'm not sure
    which direction to take on it. Basically, I allow users to add pages, and
    allow them to hide/unhide links (sub-navigation) on any page they wish. The
    problem now is in the link order. I want them to be able to choose the link
    order, and am not sure of the best way to handle this.

    I have considered up and down arrows, however I'm not really sure of the
    code I'll need to have them query the DB based on that (would I simply
    subtract or add one to the linkOrder to the DB?). So, we have also discussed
    the use of a drop-down list with a list of numbers showing the current order
    (from the DB) that each link is in, along with numbers to change the order
    by clicking a down arrow and submitting a form.

    My question is mainly - which method would be best? What would the code, or
    even the algorithm look like here? The select box code is looking ugly as
    hell because I want to echo all of this while I'm echoing the actual links,
    and the up/down arrow choices seems confusing as far as the algorithm to me.
    Here's the code block I'm using to echo values from the DB as links on the
    CMS:

    <?php
    //start a table
    echo "<table width=\"150\">< tr><td></td></tr>";

    //call the getLinks function (from a displayClass I have built)
    $links = $displayData->getLinks($page ID, $contentID, $data);

    //start looping through the records
    while($rows=mys ql_fetch_array( $links)){

    //echo links in table cells along with a hide link to have a link
    NOT show up on the actual site
    echo "<tr><td><a
    href=index.php? pageID=".$pageI D."&contentID=" .$rows['cContentID'].">".$rows['cLinkDisplay']."</a></td><td><a
    href=\"index.ph p?hideLink=".$r ows['cContentID']."&contentID=$c ontentID&pageID =$pageID\">Hide </a></td></tr>";

    }

    echo "</table>";

    ?>

    Thanks for any help


  • Adam Plocher

    #2
    Re: More CMS help

    This is how I normally achieve a sortable list:

    You should start by setting up a SortOrder (int) column. Each new
    record that get's added should cause that # to increment. If this is
    going to be a multi-user system or something you should increment it
    based on that UserID (so there aren't gaps in the number). Then when
    you want to move up simply do:

    function MoveUp($id,$rep laceID)
    {
    UPDATE table SET SortOrder=(Sort Order-1) WHERE ID=$id
    UPDATE table SET SortOrder=(Sort Order+1) WHERE ID=$replaceID
    }

    move down would be similar

    function MoveDown($id,$r eplaceID)
    {
    UPDATE table SET SortOrder=(Sort Order+1) WHERE ID=$id
    UPDATE table SET SortOrder=(Sort Order-1) WHERE ID=$replaceID
    }

    And of course on your select you would ORDER BY SortOrder. There are
    several ways you can accomplish this task, this is just the way I do
    it. I don't know if this is necessarily the best way, but as long as
    your script doesn't leave gaps in the SortOrder # you'll be fine.

    Comment

    • Jon

      #3
      Re: More CMS help

      Ok, I've added a linkOrder ID into the DB, and have my up/down arrows
      passing order=up and order=down now - My problem now is not incrementing or
      decrementing the current id chosen, it's finding the OTHER IDs that will be
      affected. Do I literally decrement every orderID for the current pageID? If
      the pageIDs are scattered, I really will not know at all what the current ID
      is save what came from the DB.

      "Adam Plocher" <aplocher@gmail .com> wrote in message
      news:1137775896 .954286.291340@ g49g2000cwa.goo glegroups.com.. .[color=blue]
      > This is how I normally achieve a sortable list:
      >
      > You should start by setting up a SortOrder (int) column. Each new
      > record that get's added should cause that # to increment. If this is
      > going to be a multi-user system or something you should increment it
      > based on that UserID (so there aren't gaps in the number). Then when
      > you want to move up simply do:
      >
      > function MoveUp($id,$rep laceID)
      > {
      > UPDATE table SET SortOrder=(Sort Order-1) WHERE ID=$id
      > UPDATE table SET SortOrder=(Sort Order+1) WHERE ID=$replaceID
      > }
      >
      > move down would be similar
      >
      > function MoveDown($id,$r eplaceID)
      > {
      > UPDATE table SET SortOrder=(Sort Order+1) WHERE ID=$id
      > UPDATE table SET SortOrder=(Sort Order-1) WHERE ID=$replaceID
      > }
      >
      > And of course on your select you would ORDER BY SortOrder. There are
      > several ways you can accomplish this task, this is just the way I do
      > it. I don't know if this is necessarily the best way, but as long as
      > your script doesn't leave gaps in the SortOrder # you'll be fine.
      >[/color]


      Comment

      • Adam Plocher

        #4
        Re: More CMS help

        Does this fix the problem? It will attempt to find the "replaceID"
        automatically. You shouldn't need to shift every item, just the item
        before or after the item you want to move.

        function MoveUp($id)
        {
        $query = "SELECT ID FROM table WHERE SortOrder=(Sort Order+1)";
        $ret = mysql_query($qu ery);
        if (mysql_num_rows ($ret) == 1)
        {
        // if 0 rows returned, don't change the sortorder
        list($replaceID ) = mysql_fetch_row ($ret);

        $query = "UPDATE table SET SortOrder=(Sort Order-1) WHERE ID=$id"
        mysql_query($qu ery);

        $query = "UPDATE table SET SortOrder=(Sort Order+1) WHERE ID=$replaceID"
        mysql_query($qu ery);
        }
        }

        Comment

        • Jon

          #5
          Re: More CMS help

          I don't understand the query here - If I'm selecting WHERE
          SortOrder=(Sort Order+1) - I don't know what sortOrder is. Do I have to pass
          the current sortOrder ID within the query string?

          "Adam Plocher" <aplocher@gmail .com> wrote in message
          news:1137779135 .046241.4690@g1 4g2000cwa.googl egroups.com...[color=blue]
          > Does this fix the problem? It will attempt to find the "replaceID"
          > automatically. You shouldn't need to shift every item, just the item
          > before or after the item you want to move.
          >
          > function MoveUp($id)
          > {
          > $query = "SELECT ID FROM table WHERE SortOrder=(Sort Order+1)";
          > $ret = mysql_query($qu ery);
          > if (mysql_num_rows ($ret) == 1)
          > {
          > // if 0 rows returned, don't change the sortorder
          > list($replaceID ) = mysql_fetch_row ($ret);
          >
          > $query = "UPDATE table SET SortOrder=(Sort Order-1) WHERE ID=$id"
          > mysql_query($qu ery);
          >
          > $query = "UPDATE table SET SortOrder=(Sort Order+1) WHERE ID=$replaceID"
          > mysql_query($qu ery);
          > }
          > }
          >[/color]


          Comment

          • Adam Plocher

            #6
            Re: More CMS help

            oops, you're absolutely right, I don't know what I was thinking. How
            about something like this

            $query = "SELECT ID FROM table WHERE SortOrder=((SEL ECT SortOrder FROM
            table WHERE ID=$id) + 1)";

            I don't have any of my PHP or MySQL in front of me, so I'm not testing
            this stuff.

            Comment

            Working...