大二下学期团队项目(分类查询)

今日主要完成了,查询排序页面的bug修改,之前写的查询排序对于热门(根据评论人数确定)排序有问题,经过排查是因为存入数据库的人数是字符串,数据库按字符串进行的排序。还有日期问题,日期中有日期与上映的地点,这样的话也不能按时间进行排序。

所以将数据库的scorenum的类型改为了int,对于日期中的杂乱数据进行了清除。

def update_time_num():
    cursor = None
    conn = None
    conn, cursor = get_conn()
    i = 5904;
    while i <=5906:
        print(i)
        i_str = '%s' % i
        i = i + 1
        # sql = "select meet from paper_data where id=" + i_str
        # cursor.execute(sql)
        # res = cursor.fetchall()
        # if(res!=()):
        # title_update=replace(res[0][0])
        try:
            sql_0="select scorenum from moviebean where id ="+i_str
            cursor.execute(sql_0)
            res = cursor.fetchall()
            print(res)
            print(res[0][0][1:len(res[0][0])])
            sql = "update  moviebean set scorenum = %s where id=" + i_str
            cursor.execute(sql, [res[0][0][1:len(res[0][0])]])
        except:
            traceback.print_exc()
            print("无此id", i)
    conn.commit()


def find_class_order(str):
    sql="select title,star,director,score,date_time,area,type_movie,scorenum,img from moviebean where 1=1 " \
        "and (type_movie like "+"'%"+str[0]+"%'"+") and (date_time like "+"'%"+str[1]+"%'"+") and(area like "+"'%"+str[2]+"%'"+") "
    if(str[3]=="star_1"):
        sql=sql+" order by score desc "
    if(str[3]=="star_0"):
        sql=sql+" order by score "
    if(str[3]=="hot_1"):
        sql=sql+" order by scorenum desc "
    if(str[3]=="hot_0"):
        sql=sql+" order by scorenum "
    if(str[3]=="time_1"):
        sql=sql+" order by date_time desc "
    if(str[3]=="time_0"):
        sql=sql+" order by date_time "
    sql=sql+"limit "+str[4]+",20 "
    print(sql)
    res = query(sql)
    print(res)
    return res

 

posted @ 2021-05-08 22:53  风吹过半夏  阅读(69)  评论(0编辑  收藏  举报