dongzhang5006 2019-02-05 14:44
浏览 53
已采纳

根据登录的用户将多个字段插入到联结表中? [关闭]

I am building a recommendation system for events ( for a charity so a charity can hold so many events etc) and in the end of this I want to display for each user a different set of events that are recommended to them based on their interests. So when a user logs in they will answer a questionnaire on their interests (3 interests to be exact for now). These interests are stored in a database as interests table. I am unsure how to link the user table (has all the users info like password name etc) with the interests table to show what interests each user has. Next then I want to show what events matches with the users interests is it possible to join three tables so that the end result will be the userID along with their interests and the corresponding events that match these interests.

User

userID

Events

eventID

Intrests

InterestID

UserIntrests

UserID

IntrestID

EventIntrests

eventID

IntrestID

I have encountered a problem when it comes to inserting data into the tables i am trying to insert the 3 chosen interests into the user interest table however it must go under the users id that is currently signed in? Any help would be greatly appreciated.

  if(isset($_POST['save']))
{
    $sql = "INSERT INTO UserInterests (id, InterestId)
    VALUES ('".$_SESSION["id"]."','".$_POST["InterestDescription"]."')";

    $result5 = mysqli_query($connection,$sql);
}
?>

<form action="questionnaire.php" method="save"> 
    <label id="first"> Interest 1</label><br>
     <input type='hidden' name='id' value=$_SESSION["id"]>
    <?php
        $select= '<select name="select">';
        while($row = mysqli_fetch_array($result)) 
    {
     $select.="<option value='".$row['InterestDescription']."'>".$row['InterestDescription']."</option>"; 
    }
       $select.='</select>';
        echo'<br></br>';
    echo $select;

    ?>
        <br><br>
        <label id="second"> Interest 2</label><br>
    <?php
    $select2= '<select name="select2">';
        while($row2 = mysqli_fetch_array($result2)) 
    {
     $select2.="<option value='".$row2['InterestDescription']."'>".$row2['InterestDescription']."</option>"; 
    }
       $select2.='</select>';
        echo'<br></br>';
    echo $select2;
                ?>
        <br><br>
        <label id="third"> Interest 3</label><br>
    <?php
    $select3= '<select name="select3">';
        while($row3 = mysqli_fetch_array($result3)) 
    {
     $select3.="<option value='".$row3['InterestDescription']."'>".$row3['InterestDescription']."</option>"; 
    }
       $select3.='</select>';
        echo'<br></br>';
    echo $select3;
                ?>

        <button type="submit" name="save">save</button>
    </form>
  • 写回答

1条回答 默认 最新

  • dongxing2030 2019-02-05 15:52
    关注

    Ok, just to get you started....

    User

    userID

    Events

    eventID

    Intrests

    InterestID

    UserIntrests

    UserID

    IntrestID

    EventIntrests

    eventID

    IntrestID

    There are the tables, you'll probably need and the primary keys in both. I'd probably do a dual primary id but that's down to you.

    They'll be more fields e.g event name obviously - but here is the start of the structure.

    Then in your system you can populate them, query the users intrests and get back events of the same intrests.

    You using phpadmin so should be able to create this using the wysiwyg

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看