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 8465487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:03:48+00:00 2026-06-10T15:03:48+00:00

I am pretty new to PHP so please be kind :). I have been

  • 0

I am pretty new to PHP so please be kind :).
I have been working on a system for a client to add products to a page, delete and edit thos products.
Now I am working on the positioning so I created a mysql entry “position”.

My table has an auto-incremated id, title, description and position.

I have managed to set the positioning to the latest upload, for example if I have 3 entrys, the latest upload will get the position 4. Here is the upload script:

//UPLOAD SCRIPT

    if (isset($_POST['upload'])) {
        $dirupload = "../images/";
        $dirupload = $dirupload . basename( $_FILES['image-upload']['name']);
        $titleupload = $_POST['title-upload'];
        $descriptionupload = $_POST['desc-upload'];
        $imageupload = ($_FILES['image-upload']['name']);
        $uploadedfileupload = $_FILES['image-upload']['tmp_name'];
        $uploadedfiletypeupload = $_FILES['image-upload']['type']; 



        $query="SELECT * FROM promotions ORDER BY position";
        $result=mysql_query($query);
        $num=mysql_num_rows($result);
        $add=$num+1;


        if (!($uploadedfiletypeupload =="image/pjpeg" OR $uploadedfiletypeupload =="image/jpeg" OR $uploadedfiletypeupload =="image/jpg")){
            echo "L'image doit être en .jpg ou .jpeg";
        }else if (move_uploaded_file($_FILES['image-upload']['tmp_name'], $dirupload)){    
            $sql="INSERT INTO promotions (title, description, position) VALUES ('$titleupload','$descriptionupload','$add')";
            if (!mysql_query($sql,$con)){
                die('Error: ' . mysql_error());
            }



            $newnameupload = "../images/" . mysql_insert_id() . ".jpg";
            rename ("../images/$imageupload","$newnameupload");    
            $orig_imageupload = imagecreatefromjpeg("../image/$newnameupload");
            $sm_imageupload = imagecreatetruecolor(96,96);
            imagecopyresampled($sm_imageupload,$orig_imageupload,0,0,0,0,96,96,imagesx($orig_imageupload),imagesy($orig_imageupload));
            imagejpeg($sm_imageupload, $newnameupload, 100);

        }else{
            echo "Problem";
        }
    }

Now my problem is with the “up” and “down” entry to change the positions, I manage to add or substract 1 to the current position, the problem is I need to do the opposite to the next or prev one, here is the “up” script:

if (isset ($_POST['up'])){
        $id=$_POST['id'];
        $position=$_POST['position'];
        $newPos=$position-1;

        mysql_query("UPDATE promotions SET position='$newPos' WHERE id='$id'");


    }

So I need to find the previous row and add 1, for example: If i have the second entry i want to put to first, click the “up” button, it gets moved up (that works) but i need to find the old first position and move it down once (that’s the problem).

Hopefully I was clear enough, and thanks in advance for any help !

  • 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-06-10T15:03:50+00:00Added an answer on June 10, 2026 at 3:03 pm

    Think this should work placed before the update to your current product

    mysql_query("UPDATE promotions SET position='$position' WHERE position='$newPos'");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to PHP and have a String which contains an HTML page.
I am new to PHP and programming in general. I have been working on
I'm pretty new to php but i'm learning pretty fast, I have a question
I'm pretty new to OOP (and also in PHP programming), and I have some
I'm pretty new to PHP so please bear with me. I'm trying to log
I am pretty new to php, but I am learning! I have a simple
I'm pretty new to PHP, so please forgive me if this question is obnoxiously
guys I'm pretty new for php i'm trying to make a login page. How
I am pretty new to PHP and MySQL and I just can't figure this
I'm pretty new to PHP, but I decided to try and make a simple

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.