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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:56:47+00:00 2026-05-15T02:56:47+00:00

Might be an easy for you guys. I am trying to sort the $_POST

  • 0

Might be an easy for you guys. I am trying to sort the $_POST variables that were sent by a form and update the sorted result in mysql. I am not sure how to do it and appreciate it anyone can help me about it.

My main.php

//I have a loop here. (omitted)
//$k will be increased by 1 every time the loop starts, so I will know the total times of the loops
//the form will be submitted to update.php


echo "<input type='hidden' name='pickTotal' value='".$k."' />";
echo "<input type='hidden' id='point' name='earnedPoint".$k."' value='".$point."' />";
echo "<input type='hidden' id='users' name='userName".$k."' value='".$userPick['user']."' />";

//loop ends

My update.php

if(isset($_POST['submit'])){

    $pickTotal=$_POST['pickTotal']; //get the total loop

    for ($p=0;$p<=$pickTotal;$p++){

        $userToBeUpdated=$_POST['userName'.$p]; 
    $userPoint=$_POST['earnedPoint'.$p]; 

       //sort the $userPoint here. 
       //I need to find out who got the most points
       //and list user's place. 1st, 2nd, 3rd...etc. 


       //update my mysql
    }

Thanks for any helps.

  • 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-15T02:56:48+00:00Added an answer on May 15, 2026 at 2:56 am

    Instead of counting up $k and $p, you should use PHPs special form name syntax:

     <input name="earnedPoint[]" value="...">
     <input name="userName[]" value="...">
    

    This way you receive both parameters as list already, $_POST[“earnedPoint”][0] till $_POST[“earnedPoint”][99] corresponds to $_POST[“userName”][0]..[99].

    Then just map both arrays:

     $sort_us = array_combine($keys=$_POST["userName"], $values=$_POST["eP"]);
     arsort($sort_us);
    

    This should get you the highest first.

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

Sidebar

Related Questions

This might be an easy one for you guys, but I'm not sure the
This might be an easy one, but I'm not really experienced with sql. I
I am hoping that there might be an easy way to do this, I
I find it not so easy as one might think to start with TDD
Might be an easy question for you guys. can't find it on google. I
This might be easy for you guys but i could't get it. I have
This might be an easy question, but I am trying to come up with
The title might not be easy to understand but it seems to me it
Hie guys i am still learning cakephp so this question might be easy but
I am pretty sure this might not be an easy task, but here goes:

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.