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.
I came with a solution with the help from Diodeus (Thanks).
I also changed a few things in the html output.