比如说有n个用户 每个用户都有关注的人的数据,粉丝的数据和用赞过的图片的数据,因为每一个用户的粉丝数,关注的人数或赞过的图片等数据的个数不一样,这样的话应该如何建立数据库,求解答,好蒙啊!
大神快救救我

解决方案 »

  1.   

    因为我没有系统的学过数据库,能否告知怎样建立多对多的中间表怎么建立吗比方说用户表user表,主键user_id,粉丝表 fan表,主键fan_id
    那么用户与粉丝多对多表建立为
    user_fans_ref(
    id bigint not null auto_increment primay key, 
    user_id bigint not null,
     fan_id bigint not null, 
    create_time datetime not null
    ) engine =innodb comment '用户粉丝表';
      

  2.   

    因为我没有系统的学过数据库,能否告知怎样建立多对多的中间表怎么建立吗比方说用户表user表,主键user_id,粉丝表 fan表,主键fan_id
    那么用户与粉丝多对多表建立为:
    create table user_fans_ref(
    id bigint not null auto_increment primay key, 
    user_id bigint not null,
     fan_id bigint not null, 
    create_time datetime not null
    ) engine =innodb comment '用户粉丝表';
      

  3.   

    存储粉丝点赞信息到数据库
    //粉丝登陆关注你信息
      //显示登录名
         lbeUserName.Text = Session["userName"].ToString();
        addPlaySum(); //调用自定义方法增加评论的点击率
      //增加点击率和用户积分
        public void addPlaySum()
        {
            //创建SQL语句,增加评论的点击率
            string sql = "update videoInfo set playSum=playSum+1,monthSum=monthSum+1 where id=" + Request["id"];
            operateData.execSql(sql);
            //创建SQL语句,查询粉丝会员名
            string sqlSel = "select userName from videoInfo where id=" + Request["id"];
            //获取会员名
            string userName = operateData.getTier(sqlSel);
            //创建SQL语句,增加用户的积分
            string sqlUpd = " update userInfo set sumMark=sumMark+1 where userName='" + userName + "'";//修改数据库点击数自加1
            //执行SQL语句
            operateData.execSql(sqlUpd);
        }
     //防止同一个粉丝重复点击
        protected void addPoll(string sqlUpd, string videoId)
        {
            //获取当前用户的ip
            string userIP = Request.UserHostAddress.ToString();
            //编写SQL查询用户ip是否已对该粉丝
            string sqlSel = "select * from videoPoll where ip='" + userIP + "' and videoId='" + videoId + "'";
            if (!(operateData.getCount(sqlSel) > 0))
            {
                //如果未参与就同意参与
                operateData.execSql(sqlUpd);
                //编写SQL语句记录用户的ip和评论id
                string sqlIns = "insert videoPoll values('" + userIP + "'," + videoId + ")";
                operateData.execSql(sqlIns);
                RegisterStartupScript("", "<script>alert('成功!')</script>");
            }
            else
            {
                RegisterStartupScript("", "<script>alert('一个内容只可以投一次')</script>");
            }//CodeGo.net/
        }
      //顶该评论内容
        protected void imgbtnD_Click(object sender, ImageClickEventArgs e)
        {
            //编写SQL语句更新顶评论内容
            string sqlUpd = "update videoInfo set flower=flower+1 where id=" + Request["id"];
            //调用自定义方法防止重复ip顶踩
            addPoll(sqlUpd, Request["id"].ToString());
            //重新显示评论详细信息
            videoInfo();
        }
        //踩该评论内容
        protected void imgbtnC_Click(object sender, ImageClickEventArgs e)
        {        string sqlUpd = "update videoInfo set tile=tile+1 where id=" + Request["id"];
            addPoll(sqlUpd, Request["id"].ToString());
            videoInfo();
        }
    //尊敬的客户朋友这里都是修改数据库的数据,按照修改字段设置数据库信息,自己随意更改添加了(修改图片略)