How to show the drop-down list in alphabetic order?

This Form works successfully, however, the Sub-Category list elements don’t appear in alphabetical order, even though I entered them into this script’s siteAdmin sub-category-input in alphabetical order. Is there a line of code that could direct the elements to appear in alphabetically order upon selecting the drop-down choices? Here’s the Form code:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<div id="upload-video">
<ul>
<li style="width:240px; text-align:right;"><strong>[var.lang_title]:</strong></li>
<li style="width:400px; text-align:left;"><input name="title" type="text" class="upload-video-form-input" value="[var.title]" size="38" />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_description]:</strong><br /></li>
<li style="width:400px; text-align:left;"><textarea rows="4" name="description" id="description" cols="29" class="upload-video-form-input">[var.description]</textarea><br />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_tags]:</strong></li>
<li style="width:400px; text-align:left;"><input name="tags" type="text" class="upload-video-form-input" value="[var.tags]" size="38" />
</li>

<input type="hidden" name="channel" value="9"/>
<li style="width:240px; text-align:right"><strong>Sub-Category:&nbsp;</strong></li>
<li style="width:450px; text-align:left;" ><select class="upload-video-form-input" id="sub_change" size="1" name="sub_cat"></select>
</li>

<input type="hidden" name="vid_upload_token" value="[var.vid_upload_token]" />

<table id="tab1">
<tbody>
<tr>
<td>
<input type="hidden" name="public_private" value="public"></li>
<input class="buttonform1" type="submit" value="UPLOAD" />
</li>
</td></tr>
</tbody>
</table>
</ul>
<input class="upload-video-form-input" type="hidden" name="form_submitted" value="yes" />
</form>
<script>javascript:ahahscript.ahah('[var.base_url]/uploader.php?sub_cat=1', 'sub_change', '', 'GET', '', this); </script>

Any help will be appreciated.

It would be easier to figure out what this form is doing if you could fix the html errors in it first. Things start getting a bit jumbled when you place an <input> and a <table> inside an unordered list <ul> without them being inside list items <li>.

2 Likes

Thanks for your reply.
I believe I’ve corrected your suggestions. Any help with my alphabetical order request will be appreciated.

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<div id="upload-video">
<ul>
<li style="width:240px; text-align:right;"><strong>[var.lang_title]:</strong></li>
<li style="width:400px; text-align:left;"><input name="title" type="text" class="upload-video-form-input" value="[var.title]" size="38" />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_description]:</strong><br /></li>
<li style="width:400px; text-align:left;"><textarea rows="4" name="description" id="description" cols="29" class="upload-video-form-input">[var.description]</textarea><br />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_tags]:</strong></li>
<li style="width:400px; text-align:left;"><input name="tags" type="text" class="upload-video-form-input" value="[var.tags]" size="38" />
</li>

<input type="hidden" name="channel" value="9"/>
<li style="width:240px; text-align:right"><strong>Sub-Category:&nbsp;</strong></li>
<li style="width:450px; text-align:left;" ><select class="upload-video-form-input" id="sub_change" size="1" name="sub_cat"></select>
</li>
</ul>
<input type="hidden" name="vid_upload_token" value="[var.vid_upload_token]" />

<table id="tab1">
<tbody>
<tr>
<td>
<input type="hidden" name="public_private" value="public"></li>
<input class="buttonform1" type="submit" value="UPLOAD" />
</td></tr>
</tbody>
</table>

<input class="upload-video-form-input" type="hidden" name="form_submitted" value="yes" />
</form>
<script>javascript:ahahscript.ahah('[var.base_url]/uploader.php?sub_cat=1', 'sub_change', '', 'GET', '', this); </script>

looks like you have to modify at least the ahahscript.ahah() method, or the data it gets from its request.

Does the data for the sub category list come from a database?

yes it comes from a database

Can you provide some direction/ideas as to modifying the ahahscript.ahah() method or data…

When you’re grabbing the data to build up the sub-category list from the db, are you using an ORDER BY clause?

Thanks for your reply.
No, I’m not aware of an “ORDER BY” clause.
Are you suggesting that if the the db column used an ORDER BY clause to keep the sub-category-names column in alphabetical order, that the Forms’ related drop-down list elements would appear in alphabetical order?

I think it’s more the query that retrieves the data for display, rather than altering the column itself.

Thanks for that reply.
Based on “it’s more the query that retrieves the data for display, rather than altering the column itself”, any idea as to what I might try, will be appreciated.

If you want to have them in a certain order, the sorting will need to be done somewhere.

It could be done server-side, either having the query do it or the PHP code before it gets returned.
Or client-side with JavaScript.

Of those options, having the query do it would be the easiest, most efficient and most reliable.

Thanks for your reply.
Can you please provide some more info, maybe an example, of what it would take having the query do it? Any additional clarification/explanation will be welcomed.

Or in the php uploader.php file (below), the sub-category(sub_cat) code seems to start aroung line 30.
I’m just looking for something to ‘display’ the drop-down choices in alphabetical order. Any ideas are appreciated.


<?php
include_once ('classes/config.php');
include_once ('classes/sessions.php');
include 'uploader_conlib.php';

$config['notification_error'] = $lang_error;

$page_title = $lang_upload_video;

if ($_SESSION['user_id'] == "") {
	header("Location: $login_out_link");;
	die();
}

$load_javascript	= 1;
$ahah			= 1;
$thickbox		= 1;

//get channel data, create "select" form fields to load into form
$sql			= "SELECT channel_id, channel_name FROM channels ORDER BY channel_name ASC";
$result1 		= @mysql_query($sql);
$count_cats 	= @mysql_num_rows($result1);
$fields_all 	= '';
$sub_fields_all	= '';
$show_fields	= '';

$fields_all .= '<option value="99999">Select One</option>';

while ($result = @mysql_fetch_array($result1)) {
    	$fields_all .= '<option value="'.$result['channel_id'].'">'.$result['channel_name'].'</option>';
}

$sub_cat_choice = (int) mysql_real_escape_string( $_GET['sub_cat'] );

if ( $sub_cat_choice ) {
	if ( $sub_cat_choice == '99999' ) {
		$sub_fields_all  .= '<select class="image_form" style="width:160px;" size="1" name="sub_cat">';
		$sub_fields_all  .= '<option value="99999">'.$lang_no_sub_categories.'</option>';
		$sub_fields_all .= '</select>&nbsp;('.$lang_select.')';
		echo $sub_fields_all;
		die();
	} else {
		$sql2			= "SELECT * from sub_channels WHERE parent_channel_id = $sub_cat_choice";
      	$query		= @mysql_query($sql2);
		$sub_fields_all  .= '<select class="image_form" style="width:160px;" size="1" name="sub_cat">';
		$sub_fields_all .= '<option value="99999">Select One</option>';
      	while ($result2 = @mysql_fetch_array($query)) {
    			$count_subs		= @mysql_num_rows($query);
    			$sub_fields_all  .= '<option value="'.$result2['sub_channel_id'].'">'.$result2['sub_channel_name'].'</option>';
     		}

     		if ( $count_subs == '' ) {
     			$sub_fields_all  .= '<option value="99999">'.$lang_no_sub_categories.'</option>';
		}

     		$sub_fields_all .= '</select>&nbsp;('.$lang_select.')';

     		echo $sub_fields_all;
	     	die();
	}
}

// grab values from form if any
$form_submitted		= $_POST['form_submitted'];
$title 			= $_POST['title'];
$description 		= $_POST['description'];
$tags 			= $_POST['tags'];
$location_recorded	= $_POST['location_recorded'];
$allow_comments 		= $_POST['allow_comments'];
$allow_embedding 		= $_POST['allow_embedding'];
$public_private 		= $_POST['public_private'];
$channel 			= $_POST['channel'];
$sub_cat			= $_POST['sub_cat'];
$thumbnail    = $_POST['thumbnail'];
$new    = $_POST['new'];
$procede 			= true;

$row = mysql_query("SELECT channel_name FROM channels WHERE channel_id = '$channel'");

while( $result = mysql_fetch_assoc($row) ) $channel_name = $result['channel_name'];

// validate form
if ($form_submitted == 'yes') {
	$post_vid_upload_token	= mysql_real_escape_string( $_POST['vid_upload_token'] );
	if ( $post_vid_upload_token != $_SESSION['vid_upload_token'] ) {
		//$spammer_msg = 'Spammer Bot detected!';
		//die($spammer_msg);
		die_spammer_alerts($referer);
	}
	foreach ($_POST as $key => $value) {
      	if ($key == 'title' || $key == 'description' || $key == 'tags' || $key == '$channel') {
            	if (!isset($value) || ($value == '')) {
                		$display_key	= @str_replace('_', ' ', $key);
                		$error_message	= $config['notification_error'];
                		$blk_notification = 1;
                		$error_message 	= $error_message . " - " . $display_key . "  - $lang_required ";
                		$procede 		= false;
            	}
        	}
    	}
    	if ( $channel == '99999' ) {
    		$error_message	= $config['notification_error'];
     		$blk_notification = 1;
     		$error_message 	= $error_message . " - $lang_select_channel";
    		$procede 		= false;
    	}
} else {
	$procede = false;
}

// display page with form error
if ($procede == false && $form_submitted == 'yes') {

	unset($_SESSION['vid_upload_token']);
	$_SESSION['vid_upload_token'] = NULL;
	$vid_upload_token			= randomcode();
	$_SESSION['vid_upload_token']	= $vid_upload_token;

	$template 		= "themes/$user_theme/templates/main_1.htm";
    	$inner_template1 	= "themes/$user_theme/templates/inner_upload_video_form.htm";
    	$TBS 			= new clsTinyButStrong;
    	$TBS->NoErr 	= true;
    	$TBS->LoadTemplate("$template");
    	$TBS->Render 	= TBS_OUTPUT;
    	$TBS->Show();
	@mysql_close();
    	die();
}
// disply clean page
if (!isset($form_submitted) || ($form_submitted == '')) {

	unset($_SESSION['vid_upload_token']);
	$_SESSION['vid_upload_token'] = NULL;
	$vid_upload_token			= randomcode();
	$_SESSION['vid_upload_token']	= $vid_upload_token;
	$template 		= "themes/$user_theme/templates/main_1.htm";
    	$inner_template1 	= "themes/$user_theme/templates/inner_upload_video_form.htm";
    	$TBS 			= new clsTinyButStrong;
    	$TBS->NoErr 	= true;
    	$TBS->LoadTemplate("$template");
    	$TBS->Render 	= TBS_OUTPUT;
    	$TBS->Show();
    	@mysql_close();
    	die();
}
if ($procede == true && $form_submitted == 'yes') {
    //=================================START OF UPLOAD=================================
    $THIS_VERSION = '2.0';
    if (isset($_GET['cmd']) && $_GET['cmd'] == 'about') {
        kak("<u><b>UBER UPLOADER FILE UPLOAD</b></u><br>UBER UPLOADER VERSION =  <b>" .
            $UBER_VERSION . "</b><br>UU_FILE_UPLOAD = <b>" . $THIS_VERSION . "<b><br>\n");
    }
    $tmp_sid = md5(uniqid(mt_rand(), true));
    ///////////////////////////////////////////////////////////////////////
    // This is where you might set your config file eg.                  //
    // if($_SESSION['user'] == "tom"){ $config_file = 'uu_tom_config'; } //
    ///////////////////////////////////////////////////////////////////////
    $config_file = $default_config_file;
    $path_to_upload_script .= '?tmp_sid=' . $tmp_sid;
    $path_to_ini_status_script .= '?tmp_sid=' . $tmp_sid;
    if ($MULTI_CONFIGS_ENABLED) {
        $path_to_upload_script .= "&config_file=$config_file";
        $path_to_ini_status_script .= "&config_file=$config_file";
    }
    //allow form to be refilled on error
    foreach($_POST as $key=>$value) {
         $$key = $value;
    }

    $template = "themes/$user_theme/templates/main_1.htm";
    $inner_template1 = "themes/$user_theme/templates/inner_upload_video.htm";
    $TBS = new clsTinyButStrong;
    $TBS->NoErr = true;// no more error message displayed.
    $TBS->LoadTemplate("$template");
    $TBS->Render = TBS_OUTPUT;
    $TBS->Show();
    @mysql_close();
    die();
    //===============================================================END OF UPLOADER================================================================
}
function die_spammer_alerts($referer) {
global $member_uploading, $user_ip, $admin_email, $site_name;

	$subject	= 'Possible Video Spamming !!';
	$message	= "The following member uploaded a possible spam video: => " . $member_uploading . "\n\n" . "The IP used: " . $user_ip . "\n";
	$to		= $admin_email;
      $from 	= $site_name;
      mail($to, $subject, $message, "From: Video demo site");
      if ( $referer > '' ) $CONFIG_AUTO_BAN_SPAMMERS == 'YES';

      if ( $CONFIG_AUTO_BAN_SPAMMERS == 'YES' ) {

      	$deny_ip	= "deny from $user_ip\n" ;
		$ban_file	= '.htaccess';
		$fo = fopen($ban_file,'a');

        	fwrite($fo,$deny_ip);
       	fclose($fo);
    	}
      write_log($message);
}
function write_log($message) {
	global $tracking_log_file;
	if (@file_exists($tracking_log_file)) {
    		$fo = @fopen($tracking_log_file, 'a');
        	@fwrite($fo, $message);
        	@fclose($fo);

    	} else {
      	$fo = @fopen($tracking_log_file, 'w');
        	@fwrite($fo, $message);
        	@fclose($fo);
    	}
exit();
}
?>

As horrible and destined to die as that code is (execution day fast approaches), it already contains an example.

SELECT channel_id, channel_name FROM channels ORDER BY channel_name ASC

SELECT * from sub_channels WHERE parent_channel_id = $sub_cat_choice

SELECT channel_name FROM channels WHERE channel_id = '$channel'

* hint - the ORDER BY

Thank you for your reply.
So, I believe you’re suggesting I need to add something to this line:

SELECT channel_id, channel_name FROM channels ORDER BY channel_name ASC

I really don’t know what that would be, any other hints would be welcomed.

Well, what you need to do is alter this line

SELECT * from sub_channels WHERE parent_channel_id = $sub_cat_choice

if this is the query that supplies the drop-down list you’re asking about, and add the ORDER BY clause. You need to ORDER BY the column name that you want it to appear in order of.

Thank you for your reply. Much appreciated.
The column that contains the sub-category names for the drop-down list is sub_channel_name.
So, that line should be changed to something like this?:

"SELECT * from sub_channels WHERE parent_channel_id = $sub_cat_choice ORDER BY sub_channel_name ";

Does that look corect?

Looks OK to me. What happens if you try it?

Thanks for your message.,

When I replace this:

} else {
		$sql2			= "SELECT * from sub_channels WHERE parent_channel_id = $sub_cat_choice";

with this:

	} else {
		sql2            = "SELECT * from sub_channels WHERE parent_channel_id = $sub_cat_choice ORDER BY sub_channel_name";

I get this:

Parse error: syntax error, unexpected ‘=’ in /home/public_html/uploader.php on line 85

Any additional help will be appreciated

You missed the $ off the variable name.