- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
$searchCondition1 = '';
$searchCondition2 = '';
$searchCondition3 = '';
$flag = false;
$sql = 'SELECT f.flight_id,
(SELECT city
FROM airports
WHERE airport_id = f.from) as _from,
(SELECT city
FROM airports
WHERE airport_id = f.to) as _to,
f.flight_date as fdate,
f.flight_time,
f.distance,
p.plain_name as plain
FROM flight f JOIN planes p
ON f.plain_id = p.plain_id
WHERE ';
$fields = 0;
if($_POST['txtSearch']){
if($_POST['txtFrom'] != ''){
$searchCondition1 = " city = '".$_POST['txtFrom']."'";
$flag = true; // set flag to TRUE
$fields++;
}
if($_POST['txtTo'] != ''){ // if To field is not empty
$searchCondition2 = " city = '".$_POST['txtTo']."'";
$flag = true; // set flag to TRUE
$fields++;
}
if ($_POST['txtDate'] != ''){ // if Date field is not empty
$searchCondition3 = " DATE(f.flight_date) = '".$_POST['txtDate']."'";
$fields++; // and inc
}
if($fields == 0){
echo "<br/><div style=\"color:red\">Please, enter at least one filed to search</div>";
}else{
if($searchCondition1 != '' && $searchCondition2 == ''){
$sql .= " f.from IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition1.")";
}
if($searchCondition1 == '' && $searchCondition2 != ''){
$sql .= " f.to IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition2.")";
}
if($searchCondition1 != '' && $searchCondition2 != ''){
$sql .= " f.from IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition1.")
AND f.to IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition2.")";
}
if($searchCondition3 != ''){
if($flag){
$sql .= " AND ".$searchCondition3;
}else{
$sql .= $searchCondition3;
}
}
include_once('database.php');
$db = createPDO();
$result = $db->query($sql);
echo '<table>
<tr>
<th>
From
</th>
<th>
To
</th>
<th>
Flight Date
</th>
<th>
Flight Time
</th>
<th>
Distance
</th>
<th>
Plane
</th>
<th>
Action
</th>
</tr>'; // create an HTML table with headers
while($row = $result->fetch()){...}
Sulik78 22.10.2011 02:41 # −1
да и вообще - похоже не слышал, как мозг включать, чтоб работал в нужном направлении - тоже не слышал
Sulik78 22.10.2011 02:44 # −1
>>airport_id
>>не когда не понимал почему во всех таблицах не использовать просто "id"?
lucidfox 22.10.2011 15:43 # −1
Lure Of Chaos 22.10.2011 16:25 # 0