【发布时间】:2021-12-23 00:30:53
【问题描述】:
请帮忙。我有一张像这样的考试预约表
Schema::create('test_bookings', function (Blueprint $table) {
$table->unsignedInteger('RequestID');
$table->string('bookingDate');
$table->string('timeSlot');
$table->unsignedInteger('nurse_id');
$table->timestamps();
});
还有一个看起来像这样的测试表
Schema::create('tests', function (Blueprint $table) {
$table->unsignedInteger('RequestID');
$table->unsignedInteger('patientID');
$table->string('barcode');
$table->string('temperature');
$table->string('pressure');
$table->string('oxygen');
$table->unsignedInteger('nurseID');
$table->timestamps();
});
只有当 test_bookings RequestID 在测试表中时,我才想显示护士的 RequestID、bookingDate、timeSlot、姓名和姓氏。这是我的护士桌
Schema::create('nurses', function (Blueprint $table) {
$table->unsignedInteger('nurseID');
$table->string('name');
$table->string('surname');
$table->string('idNumber');
$table->string('phone');
$table->string('email');
$table->unsignedInteger('suburb_id');
$table->timestamps();
$table->index('suburb_id');
});
这是我尝试过的代码
$tests = DB::table('tests')
->select('RequestID','bookingDate','timeSlot','name','surname')
->join('nurses','nurses.nurseID','test_bookings.nurse_id')
->join('test_bookings','test_bookings.RequestID','=','tests.RequestID')
->get();
【问题讨论】:
-
您在使用该代码时遇到了什么问题?
-
我的表格没有显示数据。如果我从 test_bookings 中选择并加入护士表,则会显示数据,但是当我加入测试表时,什么也没有显示。因此,我尝试了上面的代码,但仍然没有显示