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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:07:43+00:00 2026-06-09T16:07:43+00:00

I am a Junior PHP/MySQL Developer and need some help, how do I display

  • 0

I am a Junior PHP/MySQL Developer and need some help, how do I display front-end menu items by custom sorting using a text field through backend, I want to sort pages(Menut Title) by numbers like 1,2,3 …etc. in front end. It will be too better if I could understand dropdown menu sorting also from your answer. 😀 But anyway Here is my backend code but it is not working I think there needs an array which I am not understanding well:

<form name="sort_form" method="post" action="" >
<?php while($row = mysql_fetch_assoc($res)) { ?>
<tr>
    <input type="hidden" value="<?php echo $row['id']; ?>" name="id" />
    <td><input type="text" value="<?php echo $row['sort_by']; ?>" name="sort_by" size="2" maxlength="2"/></td>
    <td><?php echo $row['page_title']; ?></td>
</tr>
    <?php } ?>
<tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="Sort" /></td>
</tr>
</form>

And here is the code for when action is performed.

<?php
if(isset($_POST['submit']) == "Sort") {

    $id = intval($_POST['id']);
    $sort_by = intval($_POST['sort_by']);

    $query_update = "UPDATE `pages` SET `sort_by`='$sort_by' WHERE `id`='$id'";
    $updated = mysql_query($query_update) or die ("Update failed!");

    echo "Updated Successfuly!";

}
?>

Hope you understand!

Thanks

  • 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-09T16:07:44+00:00Added an answer on June 9, 2026 at 4:07 pm

    To sort the list you can not just update the sort_by field.

    If your table has the following data

    id  page_title  sort_by
    1   title_1         1
    2   title_2         2
    3   title_3         3
    

    What would happend if you update row 3 with a sort_by value of 1? There will be two rows that have a sort_by value of 1, which one comes first? What happends if you again update row 2 with a sort_by value of 1… there can be a lot of collisions in the sort_by field.

    However, there are several ways to get around this. One would be to simply swap sort_by values. So, when you update row 3 to a sort_by value of 1, you will also check if any sort_by values of 1 exists, and if they do, replace them with whatever row 3’s sort_by value is.

    If swapping is not the behavior your looking for you can give the sort_by field a float data type. In this case everytime you insert or move something around in your table its sort_by field will be the average of the 2 rows it is sandwiched between. If you wanted to move row 3 between rows 1 & 2 you would set row 3’s sort_by value to 1.5.

    id  page_title  sort_by
    1   title_1         1
    2   title_2         2
    3   title_3         1.5
    

    Then if you wanted to move 2 back inbetween 1 and 3 you would set 2’s sort_by value to 1.25

    id  page_title  sort_by
    1   title_1         1
    2   title_2         1.25
    3   title_3         1.5
    

    you can continue to do this for a very long time. However, since you are editing your sort by field with a textfield this does not appear to be the right choice for you.

    What I suggest is having another column in your table called “sort_by_updated_at”. Everytime you update your sort_by values set sort_by_updated_at to the current time. This way you can sort on two columns. You sort on your regular sort_by field but if there is any collisons you look at the sort_by_updated_at field and whichever row has a lower sort_by_updated_at value will precede all others.

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

Sidebar

Related Questions

I have pretty good skills in PHP , Mysql and Javascript for a junior
I'm a junior developer, who knows the basics already and have some experience as
Oh, hi. I'm a junior java developer working in my free time on some
As I continue to try and improve myself as a junior PHP developer, I
A junior programmer in our office has an unfortunate (but understandable) habit of using
I'm a junior VB.net developer with little application design knowledge. I've been reading a
Using SQL Server 2008. This is a really junior question and I could really
It's me your junior programmer extraodinaire I'm trying to display an image from my
I'm a junior developer and recently started working for a very small office where
As a junior developer, I mean without great experience, what would you do for

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.