Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从mysql数据库获取所需数据时遇到一些问题_Php_Mysql_Sql_Laravel - Fatal编程技术网

Php 从mysql数据库获取所需数据时遇到一些问题

Php 从mysql数据库获取所需数据时遇到一些问题,php,mysql,sql,laravel,Php,Mysql,Sql,Laravel,我有两个Mysql表,一个是matches,另一个是betsettings。我在betsettings表中将match_id作为外键。现在如何获取每个match_名称的betsettings信息?我想显示每个匹配项该匹配项名称下的所有下注设置信息。我正在使用laravel 匹配表: Schema::create('matches', function (Blueprint $table) { $table->increments('id'); $ta

我有两个Mysql表,一个是matches,另一个是betsettings。我在betsettings表中将match_id作为外键。现在如何获取每个match_名称的betsettings信息?我想显示每个匹配项该匹配项名称下的所有下注设置信息。我正在使用laravel

匹配表:

    Schema::create('matches', function (Blueprint $table) {
        $table->increments('id');
        $table->string('match_name');
        $table->timestamps();
    });
下注设置表:

    Schema::create('betsettings', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('match_id')->unsigned();
        $table->dateTime('close_time');
        $table->string('status')->default('active');
        $table->timestamps();
    });

    Schema::table('betsettings', function( $table) {
          $table->foreign('match_id')
          ->references('id')
          ->on('matches')
          ->onDelete('cascade')
          ->onUpdate('cascade');
         });

你们可能想看看有说服力的人际关系,更好地理解拉威尔是如何处理人际关系的

我假设每个表都有模型,让我们使用模型定义这些表之间的关系

匹配模型

public function betsettings(){
    return $this->hasOne(BetSetting:class);
}
在下注模型中

public function match(){
    return $this->belongsTo(Match:class);
}
现在,您可以使用即时加载获得每场比赛的下注设置。这里有一个例子

$match = Match::with("betsettings")->find($id);

$match->betsettings // gives you related bet settings

这是PHP吗?这是PHP之上的特定框架和/或ORM吗?请提一下,这样我们就知道我们在处理什么了。另外,在纯SQL中,您可以使用内部连接来完成此操作。我使用的是一个基于php的框架,名为laravel。我已经提到了。很抱歉,我在您的文本块末尾错过了它。你也应该添加合适的标签,这样会更明显。在这个场合,我将为您添加它们。如果你能准确地标记你的问题,那么有相关技能的人就更有可能看到它。不管怎样,到目前为止你都做了哪些尝试?你研究了什么?我甚至没有看到编写查询的尝试。如果您尝试了一些东西,请出示它,然后我们可以帮助您修复它。