0

I'm wanting to fetch all the values of the "Category" column of a table called "Category', then sort them alpha while ignoring case. What I have doesn't sort them at all. Please help, I can't quite figure how how to apply other examples to this situation. I apologize if I didn't get the formatting right for stackoverflow.

//--The purpose of this is to populate a HTML select with the proper options
    $MysqlUser = "brad";
    $MysqlPass = "mysql";
    $MysqlDatabase = "whispers";
    $connection = mysql_connect("localhost","$MysqlUser","$MysqlPass");
    if (!$connection){
        die(mysql_errno() . mysql_error());
        }

        mysql_select_db("$MysqlDatabase", $connection);
        $result = mysql_query( "SELECT Category FROM Category "); 

        while($row = mysql_fetch_assoc($result)){
        asort($row);
        foreach ( $row as $field ) {
            print "<option value=\"$field\"> $field </option>";
        }
        }
    mysql_close($connection);
    //--End HTML select

1 Answer 1

3

You need an ORDER BY in your select clause. Rows in a database table have no order, that's way you have to specify an order when you select.

SELECT Category FROM Category ORDER BY Category
Sign up to request clarification or add additional context in comments.

1 Comment

it works as promised. Thank you so much! Time to buy a FM so I can RTFM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.