Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 666477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:49:23+00:00 2026-05-13T23:49:23+00:00

I’m currently developing a website which stores bookmarks in a MySQL database using PHP

  • 0

I’m currently developing a website which stores bookmarks in a MySQL database using PHP and jQuery.

The MySQL for bookmarks looks like this (CSV format):

id,userid,link_count,url,title,description,tags,shareid,fav,date
"1";"1";"0";"img/test/google.png";"Google";"Best. Search Engine. Ever.";"google, search, engine";"7nbsp";"0";"1267578934"
"2";"1";"1";"img/test/james-brooks.png";"jTutorials";"Best. jQuery Tutorials. Ever.";"jquery, jtutorials, tutorials";"8nbsp";"0";"1267578934"
"3";"1";"2";"img/test/benokshosting.png";"Benoks Hosting";"Cheap website hosting";"Benoks, Hosting, server, linux, cpanel";"9nbsp;";"0";"1267578934"
"4";"1";"3";"img/test/jbrooks.png";"James Brooks";"Personal website FTW!";"james, brooks, jbrooksuk, blog, personal, portfolio";"1nbsp";"0";"1267578934"
"6";"1";"4";"img/test/linkbase.png";"LinkBase";"Store and organise your bookmarks and access them from anywhere!";"linkbase, bookmarks, organisation";"3nbsp";"0";"1267578934"
"5";"1";"5";"img/test/jtutorials.png";"jTutorials";"jQuery tutorials, videos and examples!";"jquery, jtutorials, tutorials";"2nbsp";"0";"1267578934"

I’m using jQuery Sortable to move the bookmarks around (similar to how Google Chrome does). Here is the JavaScript code I use to format the bookmarks and post the data to the PHP page:

$(".bookmarks").sortable({scroll: false, update: function(event, ui){
        // Update bookmark position in the database when the bookmark is dropped
        var newItems = $("ul.bookmarks").sortable('toArray');
        console.log(newItems);
        var oldItems = "";
        for(var imgI=0;imgI < newItems.length;imgI++) {
            oldItems += $("ul.bookmarks li#" + imgI + " img").attr("id") + ",";
        }
        oldItems = oldItems.slice(0, oldItems.length-1);
        console.log("New position: " + newItems);
        console.log("Old position: " + oldItems);

        // Post the data 
        $.post('inc/updateBookmarks.php', 'update=true&olditems=' + oldItems + "&newitems=" + newItems, function(r) {
            console.log(r);
        });
    }
});

The PHP page then goes about splitting the posted arrays using explode, like so:

if(isset($pstUpdate)) {
    // Get the current and new positions
    $arrOldItems = $_POST['olditems'];
    $arrOldItems = explode(",", $arrOldItems);

    $arrNewItems = $_POST['newitems'];
    $arrNewItems = explode(",", $arrNewItems);

    // Get the user id
    $usrID = $U->user_field('id');

    // Update the old place to the new one
    for($anID=0;$anID<count($arrOldItems);$anID++) {
        //echo "UPDATE linkz SET link_count='" . $arrNewItems[$anID] . "' WHERE userid='" . $usrID . "' AND link_count='" . $arrOldItems[$anID] . "'\n";
        //echo "SELECT id FROM linkz WHERE link_id='".$arrOldItems[$anID]."' AND userid='".$usrID."'";

        $curLinkID = mysql_fetch_array(mysql_query("SELECT id FROM linkz WHERE link_count='".$arrOldItems[$anID]."' AND userid='".$usrID."'")) or die(mysql_error());
        echo $arrOldItems[$anID] . " => " . $arrNewItems[$anID] . " => " . $curLinkID['id'] . "\n";

        //mysql_query("UPDATE linkz SET link_count='" . $arrNewItems[$anID] . "' WHERE userid='" . $usrID . "' AND link_count='" . $curLinkID['id'] . "'") or die(mysql_error());

        // Join a string with the new positions
        $outPos .= $arrNewItems[$anID] . "|";
    }

    echo substr($outPos, 0, strlen($outPost) - 1);
}

So, each bookmark is given it’s own link_count id (which starts from 0 for each user). Every time a bookmark is changed, I need the link_count to be changed as needed. If we take this array output as the starting places:

Array
(
    [0] => 0
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
)

Each index equalling the link_count position, the resulting update would become:

Array
(
    [0] => 1
    [1] => 0
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 2
)

I have tried many ways but none are successful.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:49:23+00:00Added an answer on May 13, 2026 at 11:49 pm

    After some long hours of Googling, searching, and testing, I’ve come up with something that is practical, but not 100%.

    // Update the old place to the new one
    for($anID=0;$anID<count($arrOldItems);$anID++) {
        if($oldCycle != $arrNewItems[$anID]) {
            if($arrOldItems[$anID] != $arrNewItems[$anID]) {
                $sQuery = "UPDATE linkz AS rule1 JOIN linkz AS rule2 ON (rule1.link_count = $arrOldItems[$anID] AND rule2.link_count = $arrNewItems[$anID]) OR ( rule1.link_count = $arrNewItems[$anID] AND rule2.link_count = $arrOldItems[$anID]) SET rule1.link_count = rule2.link_count, rule2.link_count = rule1.link_count";
                mysql_query($sQuery) or die(mysql_error());
                // Now set a temporary variable which we'll check later
                $oldCycle = $anID;
            }
        }else{
            $oldCycle = NULL;
        }
    }
    

    It kind of works, however it does not allow you to swap the same bookmarks twice. I’ll figure something out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.