dpvp56187 2016-03-24 09:21
浏览 29

强制矩阵计划数据提取问题

I am working on Forced Matrix plan website. It is 2X8 Matrix. Here user can add 2 frontline on its first level and 4 on its second level and so on. Now i am find the way in mysql that will satisfy my condition. my condition is that search sponsor left and right leg anf if empty then insert new member under that sponsor and if not then search sponsor's member left and right leg and so on.

Hope you understand well. Here is screenshort of my table data where i am saving the data with relation of sponsor and member with position.

enter image description here

  • 写回答

1条回答 默认 最新

  • dqrm8199 2016-03-24 09:38
    关注

    Please, for future notice, provide code or/and ideas that you have already tried. This is not the place to just ask people to do things for you.

    class Database
    {
        protected $db;
        public function __construct()
        {
            $this->db = new PDO("mysql:host=localhost;dbname=example","user","pass");
        }
    
        public function is_Empty($left,$right)
        {
            $search = $this->db
                           ->prepare("SELECT * FROM table WHERE ... OR ...");
            $search->execute(array(
                           ':left' => $left,
                           ':right' => $right
                     ));
            if($prepare->fetchAll() == null)? return false : return true;
        }
    }
    

    The above code explains the principle, we're checking firstly if the person exists by using an SQL statement. Once the PDO executes the SQL query, it will return an Object. If the Object is null then we know that the user does not exist so we return false, if it does exist, we return true.

    You can then do something like so:

    class DatabaseExtension extends Database
    {
        public function insert($name,$right, ect...)
        {
            $insert = $this->db->prepare("INSERT INTO...");
        }
    }
    

    It can be called and used from $_GET requests or $_POST requests from a HTML web form which sends to a handler PHP file like so:

    $dbHandler = new Database;
    $dbHandler->inserting = new DatabaseExtension;
    if($dbHandler->is_Empty($_GET['left'],$_GET['right']):
        $dbHandler->insert($_GET['name'],$_GET['right'],etc...);
    else:
        echo "Sorry, this sponsor is already filled...";
    endif;
    

    This code is NOT exact and will not be your solution. It is to give you an idea scope to solve your problem.

    Also note that is method is very Object-Orientated so if you're unfamiliar with any of this code or the use of Classes, I suggest you research before you create another post like: "What is a Class, Please make this for me."

    There are plenty of other Connection protocols/API's you can use rather than PDO although I'd recommend PDO due to both SQLi,SQL (and if you're just plain... urgh...) ODBC becoming very depreciated in newer versions of PHP.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?