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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:58:28+00:00 2026-05-28T00:58:28+00:00

How can I create an array of items from a generated list using a

  • 0

How can I create an array of items from a generated list using a select box to order the items and deliminate them by a comma.

Example…

I have a list of items generated by the id in the database with a select box associated with the item.

<?php
$sql = mysql_query("SELECT id, title FROM songs WHERE id='$id' ORDER BY title ASC");

  while($row = mysql_fetch_array($sql)){
    $id = $row['id'];
    $title = $row['title'];
    $song_chart .= '

      <div id="$id">

        <select>
          <option val="1">1</option>
          <option val="2">2</option>
          <option val="3">3</option>
          <option val="4">4</option>
          //etc...
        </select>

        <a href="page.php?id='.$id.'">'.$title.'</a>

      </div>';
  }
$song_chart .= '<button></button>';
echo $song_chart;
?>

I have multiple items that I would like to select a value for.

If the value is greater than 0 than I want to grab the ‘id’ from the item the select is associated with and order all of the items by the selection (not the id).

Then I would like to post the information and place it into a comma delimited array to insert into my database.

I currently do not have any code that I have actually tried, I am really not sure how to go about this. Any help would be greatly appreciated. Thanks in advance!

EDIT

The output of the above would look like this…

<div id="1">
  <select>
    <option val="1">1</option>
    <option val="2">2</option>
    <option val="3">3</option>
    <option val="4">4</option>
    //etc...
  </select>

  <a href="page.php?id=1">one</a>

</div>
<div id="2">
  <select>
    <option val="1">1</option>
    <option val="2">2</option>
    <option val="3">3</option>
    <option val="4">4</option>
    //etc...
  </select>

  <a href="page.php?id=2">two</a>

</div>
<div id="3">
  <select>
    <option val="1">1</option>
    <option val="2">2</option>
    <option val="3">3</option>
    <option val="4">4</option>
    //etc...
  </select>

  <a href="page.php?id=3">three</a>

</div>
<div id="4">
  <select>
    <option val="1">1</option>
    <option val="2">2</option>
    <option val="3">3</option>
    <option val="4">4</option>
    //etc...
  </select>

  <a href="page.php?id=4">four</a>

</div>

<button></button>

Then on submit I would like to reorganize the generated id’s accourding to the selected value and place then in an array/string like so…

var arr = '2, 3, 1, 4';

and post them to the database.

  • 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-28T00:58:29+00:00Added an answer on May 28, 2026 at 12:58 am

    I came with a solution with the help from Diodeus (Thanks).

    $(document).ready(function(){
      $('.selection').value(""); // clears the values
      $('selection option').click(function(){ // when option is clicked
    
        s=new Array(); // create array
        $("select option:selected").each(function(){
         // check to see which values are selected
          var v = $(this).val();
    
          if(v != ""){ // if the value is not empty.
            s.push(v); 
          }
    
        });
    
      });
      $("#submitList").click(function(){
        if(s != ""){
          alert(s);//or submit the list
        }
      });
    });
    

    I also changed a few things in the html output.

    <div id="3">
      <select class='selection'>
        <option></option>
        <option val="1,id">1</option>
        <option val="2,id">2</option>
        <option val="3,id">3</option>
        <option val="4,id">4</option>                      
        //etc...                    
      </select>
      <a href="page.php?id=3">three</a>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can c++ create array of pointers to different classes dynamically loaded from dll? ps.without
I can create a sparse php array (or map) using the command: $myarray =
I can create an array of buttons in Windows Form but how can i
How can I create an array of email addresses contained within a block of
How can I create an array of namespaces? And because it seems like a
How can I create an empty one-dimensional string array?
I'm trying to create an array of strings that can be randomized and limited
i am querying the DB as follows: $result=mysql_query(SELECT name,items FROM mytable WHERE user_id='$id'); now,i
For example if i have to create custom list view about type of food,
in my application user can create an array of elements.E.g. he can assign a

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.