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

  • SEARCH
  • Home
  • 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 7400121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:09:21+00:00 2026-05-29T04:09:21+00:00

I am using a nice piece of code to reorder db content using drag

  • 0

I am using a nice piece of code to reorder db content using drag and drop. I can get it to work locally by enabling the PDO extension in the php.ini file but my hosting package (shared) does not allow PDO and MySQLi simultaneously. I am unfamiliar with PDO and I would appreciate any help in rewriting the following segment to work with MySQLi, if possible.
Thanks.

<?php
if (isset($_POST['orders'])) {

} else {
    echo json_encode(array('error' => true));
}

$orders = explode('&', $_POST['orders']);

$array = array();

foreach($orders as $item) {
    $item = explode('=', $item);
    $item = explode('_', $item[1]);
    $array[] = $item[1];
}

try {

    $objDb = new PDO('mysql:host=localhost;dbname=test', 'user', 'pw');
    $objDb->exec("SET CHARACTER SET utf8");

    foreach($array as $key => $value) {
        $key = $key + 1;
        $sql = "UPDATE `artwork` 
               SET `listorder` = ?
               WHERE `id` = ?";
               echo $sql;

        $objDb->prepare($sql)->execute(array($key, $value));        
    }

    echo json_encode(array('error' => false));

} catch(Exception $e) {

    echo json_encode(array('error' => true));

}
  • 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-29T04:09:22+00:00Added an answer on May 29, 2026 at 4:09 am

    My recommendation? Find another host. Going from PDO to mysqli is not a good idea, because you will waste time porting code into a less portable state.

    — Edit —

    You can try the following code snippet, if it doesn’t work it should get you started. I couldn’t test it because none of my servers have mysql* modules compiled.

    $dbo = new mysqli('localhost', 'user', 'password', 'database');
    
    if (mysqli_connect_error()) {
        echo sprintf('Unable to connect: ErrNo: (%d), ErrMsg: (%s)', mysqli_connect_errno, mysqli_connect_error());
        exit;
    }
    
    foreach ($array as $key => $value) {
    
        $key = $key + 1;
    
        $sql =  "UPDATE `artwork` SET `listorder` = " . (int) $key . "  WHERE `id` = " . (int) $value;
    
        $dbo->query($sql);
    }
    
    $dbo->close();
    

    You can get more information on mysqli query and other functions here.

    Anyway, good luck.

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

Sidebar

Related Questions

Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
Is there a nice and tested piece of code out there that I can
I am using nice little piece of xstream to perform serialization. I have the
I'm using this piece of code from a fellow SO user: $(#rightSubMenu).mousemove(function(e){ console.log('executed'); var
Hey, I've got this nice little piece of code, much like all the other
StackOverflow user jolson had a very nice piece of code that exemplifies how one
Is there a simple script or piece of code I can add to my
I am using a nice jquery slideshow plugin I found and trying to get
I'm using the very nice PhotoSlider script from http://opiefoto.com/articles/photoslider to create a slide show
Is there a quick and nice way using linq?

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.