function list_msg($order, $start_page, $reading_msg_id = - 1)
{
    global $default_dbname, $user_tablename, $dbname;
    global $default_font, $default_font_size, $cur_page, $max_msg_per_page, 
       $keyword, $search_option, $search_type, $PHP_SELF;
    global $header_cell_bgcolor, $number_cell_width, 
       $header_cell_font_color, $id_cell_width;
    global $msg_cell_bgcolor, $board, $msg_total, $thread_depth_limit, 
       $menu_colspan;
    global $space_icon, $main_icon, $thread_icon, $new_main_icon, 
       $new_thread_icon, $reading_icon, $default_hspace, $status_bar;

    $search_sql = "";

    $keyword = eregi_replace("\+", " ", $keyword);

    $keyword_list = split(" ", $keyword);
    $total_array_num = count($keyword_list);



    if($order == "desc") {
        $result = mysql_query("select msg_id, thread_id, msg_subject, 
           userid, msg_hit, msg_date, thread_depth from $board order by 
           thread_id desc, thread_info limit $start_page, 
           $max_msg_per_page");
        if(!$result) {
            error_message('DB_ERROR', '', "L-1");
            exit;
        }
    }
    else if ($order == "asc") {
        $result = mysql_query("select msg_id, thread_id, msg_subject, 
           userid, msg_hit, msg_date, thread_depth from $board order by 
           thread_id limit $start_page, $max_msg_per_page");
        if(!$result) {
            error_message('DB_ERROR', '', "L-2");
            exit;
        }
    }

    $num_rows = mysql_num_rows($result);

    for ($i = 0; $i < $num_rows; $i++)
    {
        $query_data = mysql_fetch_row($result);
        $msg_id = $query_data[0];
        $thread_id = $query_data[1];
        $subject = stripslashes($query_data[2]);
        $userid = stripslashes($query_data[3]);
        $msg_hit = $query_data[4];
        $msg_date = $query_data[5];
        $thread_depth = $query_data[6];

        $datetime = split(" ", $msg_date);
        $msg_date = $datetime[0];
        $msg_time = $datetime[1];

        if($msg_id == $reading_msg_id) {
            $leading_icon = "<img src=\"$reading_icon\" 
                     hspace=\"$default_hspace\">";
        }
        else {
            if($msg_date == date( "Y-m-d" )) {
                $leading_icon = "<img src=\"$new_main_icon\" 
                        hspace=\"$default_hspace\">";
            }
            else {
                $leading_icon = "<img src=\"$main_icon\" 
                        hspace=\"$default_hspace\">";
            }
        }

        if($order == "desc") {
            $hspace = 0;

            for($j=0; $j < $thread_depth; $j++) {
                $hspace += $default_hspace;
                if($j == $thread_depth_limit) break;
            }
            if($thread_depth > 0) {
                $leading_icon = "<img src=\"$space_icon\" 
                        hspace=\"$hspace\">";

                if($msg_id == $reading_msg_id) {
                    $leading_icon .= "<img src=\"$reading_icon\" 
                             hspace=\"$default_hspace\">";
                }
                    else {
                    if($msg_date == date( "Y-m-d" )) {
                        $leading_icon .= "<img src=\"$new_thread_icon\" 
                                 hspace=\"$default_hspace\">";
                    }
                    else {
$leading_icon .= "<img src=\"$thread_icon\" hspace=\"$default_hspace\">";
                    }
                }
            }

        }

    }
}