สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network
Moderator: mindphp, ผู้ดูแลกระดาน
-
makup
- PHP Super Member
- โพสต์: 398
- ลงทะเบียนเมื่อ: 05/10/2020 10:02 am
โพสต์ที่ยังไม่ได้อ่าน
โดย makup »
มีการส่งค่า Form มา showAirflight.blade.php
โค้ด: เลือกทั้งหมด
<thead class="thead-dark">
<form class="" method="get" name="search" action="/searchAirflight/search">
<tr>
<th scope="col">ลำดับ</th>
<th scope="col">
<select name="name" id="name" >
<option value="0" selected="selected">---- เลือกทั้งหมด ----</option>
<?php $number = 1; ?>
@foreach($airport as $airports)
<option value="{{$airports->id}} " {{ ( $airports->id == $flight_1['name']) ? 'selected' : '' }}
>{{$number}}<?php echo ".";?>{{$airports->name}} </option>
<?php $number++; ?>
@endforeach
</select>
<br><br>ชื่อที่ตั้งสนามบิน</th>
<th scope="col">
<select name="name_airline" id="name_airline">
<option value="0" selected="selected">---- เลือกทั้งหมด ----</option>
<?php $number = 1; ?>
@foreach($airline as $airlines)
<option value="{{$airlines->id}}" {{ ( $airlines->id == $flight_1['name_airline']) ? 'selected' : '' }}
>{{$number}}<?php echo ".";?>{{$airlines->name_airline}}</option>
<?php $number++; ?>
@endforeach
</select>
<br><br>ชื่อสายการบิน</th>
<th scope="col">
<select name="path" id="path">
<option value="0" selected="selected">---- เลือกทั้งหมด ----</option>
<?php $number = 1; ?>
@foreach($airport as $airports)
<option value="{{$airports->id}}" {{ ( $airports->id == $flight_1['path']) ? 'selected' : '' }}
>{{$number}}<?php echo ".";?>{{$airports->name}}</option>
<?php $number++; ?>
@endforeach
</select>
<br><br>สนามบินปลายทาง</th>
<th scope="col">วันที่</th>
<th scope="col">เวลาออกเดินทาง</th>
<th scope="col">ราคา</th>
<th scope="col">รุ่นเครื่องบิน</th>
<th scope="col">แก้ไข</th>
<th scope="col">
<button type="submit" name="submit" class="btn btn-primary" name="submit">ค้นหา</button>
<br><br>ลบ</th>
</tr>
</form>
</thead>
และส่งเข้าไปที่ Controller_show_airflight.php วิ่งที่ไป Function search()
- 90.JPG (72.14 KiB) Viewed 1394 times
ตัวอย่าง Code : Controller_show_airflight.php
โค้ด: เลือกทั้งหมด
public function search(Request $request)
{
$name = $request->name;
$name_airline = $request->name_airline;
$path = $request->path;
$flight_1 = $request->all();
$flight = Airflight::where('id_airport' , '=' , "{$name}")
->OrWhere('id_airline' , '=' , "{$name_airline}")
->OrWhere('path' , '=' , "{$path}")
->paginate(5);
return view("showAirflight" )
->with('flight', $flight)
->with('flight_1', $flight_1)
->with('airport',Airport::all())
->with('airline',Airline::all())
->with('flight_path',Airflight::all())
;
}
-
mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41379
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
-
ติดต่อ:
โพสต์ที่ยังไม่ได้อ่าน
โดย mindphp »
โค้ด: เลือกทั้งหมด
$flight = Airflight::where('id_airport' , '=' , "{$name}")
->OrWhere('id_airline' , '=' , "{$name_airline}")
->OrWhere('path' , '=' , "{$path}")
->paginate(5);
เช็คก่อนว่า คนค้นหา เขาค้นหา ส่วนไหนเข้ามาก่อน เอามาทำเป็นคำสั่ง SQL เพื่อค้นหา
ไม่จำเป็นต้อง ใช้ or สำหรับข้อมูลที่ไม่เกี่ยวข้อง
-
makup
- PHP Super Member
- โพสต์: 398
- ลงทะเบียนเมื่อ: 05/10/2020 10:02 am
โพสต์ที่ยังไม่ได้อ่าน
โดย makup »
mindphp เขียน: ↑30/10/2020 7:50 pm
โค้ด: เลือกทั้งหมด
$flight = Airflight::where('id_airport' , '=' , "{$name}")
->OrWhere('id_airline' , '=' , "{$name_airline}")
->OrWhere('path' , '=' , "{$path}")
->paginate(5);
เช็คก่อนว่า คนค้นหา เขาค้นหา ส่วนไหนเข้ามาก่อน เอามาทำเป็นคำสั่ง SQL เพื่อค้นหา
ไม่จำเป็นต้อง ใช้ or สำหรับข้อมูลที่ไม่เกี่ยวข้อง
รับทราบครับ
-
makup
- PHP Super Member
- โพสต์: 398
- ลงทะเบียนเมื่อ: 05/10/2020 10:02 am
โพสต์ที่ยังไม่ได้อ่าน
โดย makup »
thatsawan เขียน: ↑30/10/2020 7:48 pm
echo $flight ; ดูคำสั่ง SQL หน่อย
ใช้ echo ไม่แสดงผล , ต้องใช้ print_r ครับ
Illuminate\Pagination\LengthAwarePaginator Object ( [total:protected] => 7 [lastPage:protected] => 2 [items:protected] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\Airflight Object ( [connection:protected] => mysql [table:protected] => airflights [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 58 [id_airport] => 12 [id_airline] => 9 [path] => 13 [date] => 2020-10-10 [timeout] => 22:56:00 [price] => 200.00 [model_aircraft] => AH-78 [created_at] => 2020-10-30 11:53:23 [updated_at] => 2020-10-30 11:53:23 ) [original:protected] => Array ( [id] => 58 [id_airport] => 12 [id_airline] => 9 [path] => 13 [date] => 2020-10-10 [timeout] => 22:56:00 [price] => 200.00 [model_aircraft] => AH-78 [created_at] => 2020-10-30 11:53:23 [updated_at] => 2020-10-30 11:53:23 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [classCastCache:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) [1] => App\Airflight Object ( [connection:protected] => mysql [table:protected] => airflights [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 59 [id_airport] => 12 [id_airline] => 10 [path] => 13 [date] => 2020-10-11 [timeout] => 20:55:00 [price] => 1000.00 [model_aircraft] => AH-78 [created_at] => 2020-10-30 11:53:58 [updated_at] => 2020-10-30 11:53:58 ) [original:protected] => Array ( [id] => 59 [id_airport] => 12 [id_airline] => 10 [path] => 13 [date] => 2020-10-11 [timeout] => 20:55:00 [price] => 1000.00 [model_aircraft] => AH-78 [created_at] => 2020-10-30 11:53:58 [updated_at] => 2020-10-30 11:53:58 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [classCastCache:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) [2] => App\Airflight Object ( [connection:protected] => mysql [table:protected] => airflights [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 61 [id_airport] => 14 [id_airline] => 10 [path] => 13 [date] => 2020-10-04 [timeout] => 21:58:00 [price] => 1000.00 [model_aircraft] => AH-52 [created_at] => 2020-10-30 11:55:05 [updated_at] => 2020-10-30 11:55:05 ) [original:protected] => Array ( [id] => 61 [id_airport] => 14 [id_airline] => 10 [path] => 13 [date] => 2020-10-04 [timeout] => 21:58:00 [price] => 1000.00 [model_aircraft] => AH-52 [created_at] => 2020-10-30 11:55:05 [updated_at] => 2020-10-30 11:55:05 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [classCastCache:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) [3] => App\Airflight Object ( [connection:protected] => mysql [table:protected] => airflights [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 62 [id_airport] => 13 [id_airline] => 10 [path] => 13 [date] => 2020-10-10 [timeout] => 21:58:00 [price] => 1000.00 [model_aircraft] => AH-52 [created_at] => 2020-10-30 11:55:43 [updated_at] => 2020-10-30 11:55:43 ) [original:protected] => Array ( [id] => 62 [id_airport] => 13 [id_airline] => 10 [path] => 13 [date] => 2020-10-10 [timeout] => 21:58:00 [price] => 1000.00 [model_aircraft] => AH-52 [created_at] => 2020-10-30 11:55:43 [updated_at] => 2020-10-30 11:55:43 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [classCastCache:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) [4] => App\Airflight Object ( [connection:protected] => mysql [table:protected] => airflights [primaryKey:protected] => id [keyType:protected] => int [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [id] => 63 [id_airport] => 13 [id_airline] => 10 [path] => 14 [date] => 2020-10-23 [timeout] => 20:58:00 [price] => 5000.00 [model_aircraft] => AH-52 [created_at] => 2020-10-30 11:56:12 [updated_at] => 2020-10-30 11:56:12 ) [original:protected] => Array ( [id] => 63 [id_airport] => 13 [id_airline] => 10 [path] => 14 [date] => 2020-10-23 [timeout] => 20:58:00 [price] => 5000.00 [model_aircraft] => AH-52 [created_at] => 2020-10-30 11:56:12 [updated_at] => 2020-10-30 11:56:12 ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [classCastCache:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [timestamps] => 1 [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [perPage:protected] => 5 [currentPage:protected] => 1 [path:protected] =>
http://127.0.0.1:8000/searchAirflight/search [query:protected] => Array ( ) [fragment:protected] => [pageName:protected] => page [onEachSide] => 3 [options:protected] => Array ( [path] =>
http://127.0.0.1:8000/searchAirflight/search [pageName] => page ) )
-
-
- 2 ตอบกลับ
- 3599 แสดง
-
โพสต์ล่าสุด โดย powerbeer
22/11/2022 9:08 pm
-
-
- 2 ตอบกลับ
- 4373 แสดง
-
โพสต์ล่าสุด โดย mindphp
24/12/2021 10:50 am
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 137