View Full Version : Sorting MySQL results multiple columns

04-14-2014, 09:03 PM
I am working on setting up a media page for a site with sermon messages. I currently have the database set up to display a drop-down of each bible book listed in the database (one per sermon). This drop-down, when a book is selected, the page is then refreshed to show the messages from that book. i would like to add the option of adding a second bible book to certain messages which could also show up in the drop-down. The way I currently have it set up, i don't see a way of doing it. the web page i am referring to is: http://www.lifeinchristministries.com/resources/media/

here is my code for sorting the passages by book:


$sortbypassage2 = "Select Book from Drop-Down--";
$addoption = "";


$addoption = "<option value='000All Books'>All Books</option>";

echo '<form action="../media/#messages" method="post">
<select name="passage" width="200" style="width: 200px" onchange="javascript: submit()">
<option selected="selected">' .$sortbypassage2. '</option>' .$addoption;

//Retrieves data from MySQL
$data = mysql_query("SELECT DISTINCT passage FROM audio_messages ORDER BY passage ASC") or die(mysql_error());
//Puts it into an array
while($row = mysql_fetch_array( $data ))
$currentpassage = $row['passage'];
$currentpassage2 = substr($currentpassage, 3);

echo '
<option value="' .$currentpassage. '">' .$currentpassage2. '</option>';
echo "</select></form>";

i set up another MySQL column with the title 'passage2' for the second book of the bible.

I thought maybe changing the column to a 'varchar' or something (sort of like a keyword field) where i could have them both in one column, but then would have to figure out how to sort separate values within a column, and would prefer to not do this option as i think I may have to update each field value.

Thank you for any help anyone can offer!