doudong8713 2015-06-16 06:55
浏览 46
已采纳

让新用户自动关注用户

I am working on a php site with uses mysql as database, now my site is a social network like site where users follow each other, now if a user joins in he is following nobody so his stream remains empty so they leave the site quickly as well,i want users to be following my account account automatically when he joins in. Can you please tell me how to do it

here are the two tables

Table structure for table sn_users

CREATE TABLE IF NOT EXISTS `sn_users` (
`id` int(11) NOT NULL,
  `username` varchar(225) NOT NULL,
  `email` varchar(225) NOT NULL,
  `password` varchar(225) NOT NULL,
  `name` varchar(225) DEFAULT NULL,
  `picture` varchar(100) NOT NULL,
  `cover` varchar(100) DEFAULT NULL,
  `job` varchar(225) DEFAULT NULL,
  `address` varchar(225) DEFAULT NULL,
  `date` int(11) NOT NULL,
  `reg_id` text,
  `active` int(11) NOT NULL DEFAULT '1'
) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;

Table structure for table sn_follows

CREATE TABLE IF NOT EXISTS `sn_follows` (
`id` int(11) NOT NULL,
  `from` int(11) NOT NULL,
  `to` int(11) NOT NULL,
  `date` int(11) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=74 DEFAULT CHARSET=utf8;
  • 写回答

2条回答 默认 最新

  • dongshi1914 2015-06-16 06:59
    关注

    Run the query when the user get registerd.

    <?
    //Register query
    $con = mysqli_connect("[HOST", "[USER]", "[PASS]", "[DB]");
    $query1 = "INSERT INTO sn_users
              (username, email, password, name, picture, cover, job, address, date, reg_id, active)
              VALUES
              ('$username', '$email', '$password', '$name', '$picture', '$cover', '$job', '$address', 'date', 'reg_id', 'active')";
    mysqli_query($con, $query);
    
    //Auto follow query
     $query2 = "INSERT INTO sn_follows
                (`id`, `from`, `to`, `date`)
                VALUES
                ([ID], '[NEW REGISTERD ACCOUNT], '[YOUR ACCOUNT]', '[DATE]')";
     mysqli_query($con, $query2);
    

    Hints:

    • Make of the field id in your database an auto_increment
    • Make sure you put a hashed password in the database
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法