MySQL Search met 5 zoekvelden
Eerst wil ik mezelf even voorstellen, ik ben Daan, 12 jaar, en wel redelijk ervaren met PHP.
Nu wil ik graag een zoekveldje maken waar ik op 5 dingen kan zoeken.
Ik heb hiervoor deze PHP code gemaakt.
Even ter info, het formulier zit in een ander bestand.
Code (php)
1
2
3
4
5
6
7
8
9
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
2
3
4
5
6
7
8
9
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<table style="width:100%">
<tr style="font-weight:bold">
<td>Pilot</td><td>Dep</td><td>Des</td><td>Callsign</td><td>A/C</td><td>Duration</td><td>Distance</td><td>Start Time</td><td>Stop Time</td><td>Status</td>
</tr>
<?php
// een paar functies om tijd goed neer te zetten en te formateren
function FormatTime($minutes) {
$time = $minutes;
$hours = $time / 60;
$minutes = round(($hours - floor($hours)) * 60);
$hours = floor($hours);
if (strlen($hours) == 0) $hours = "0";
if (strlen($minutes) == 1) $minutes = "0".$minutes;
if (strlen($minutes) == 0) $minutes = "00";
$time = $hours.":".$minutes;
return $time;
}
function FormatTimeAgo($timediff, $lang) {
if ($timediff < 60)
{
if ($lang == "en") $ago = "$timediff sec";
}
elseif ($timediff < 3600)
{
$timediff2 = floor($timediff / 60);
$timediff = $timediff - ($timediff2 * 60);
if (strlen($timediff) == 1) $timediff = "0$timediff";
if ($lang == "en") $ago = "$timediff2:$timediff min";
}
else
{
$timediff2 = floor($timediff / 60);
$timediff = $timediff - ($timediff2 * 60);
if (strlen($timediff) == 1) $timediff = "0$timediff";
$timediff3 = floor($timediff2 / 60);
$timediff2 = $timediff2 - ($timediff3 * 60);
if (strlen($timediff2) == 1) $timediff2 = "0$timediff2";
if ($lang == "en") $ago = "$timediff3:$timediff2 hrs";
}
if ($lang == "en") $ago .= " ago";
return $ago;
}
// dbconnectie eraan
include("dbconnect.inc.php");
// vars halen uit een formulier
if(isset($_POST["name"])) $pilotidset=$_POST["name"];
if(isset($_POST["cs"])) $csset=$_POST["cs"];
if(isset($_POST["ac"])) $acset=$_POST["ac"];
if(isset($_POST["dep"])) $depset=$_POST["dep"];
if(isset($_POST["dest"])) $destset=$_POST["dest"];
// als de vars gezit zijn, zetten we een andere var zo dat de query daarna wordt ingesteld
if(isset($pilotidset)) { $set="1"; }
if(isset($csset)) { $set="2"; }
if(isset($acset)) { $set="3"; }
if(isset($depset)) { $set="4"; }
if(isset($destset)) { $set="5"; }
if((isset($pilotidset)) && (isset($csset))) { $set="12"; }
if((isset($pilotidset)) && (isset($acset))) { $set="13"; }
if((isset($pilotidset)) && (isset($depset))) { $set="14"; }
if((isset($pilotidset)) && (isset($destset))) { $set="15"; }
if((isset($csset)) && (isset($acset))) { $set="23"; }
if((isset($csset)) && (isset($depset))) { $set="24"; }
if((isset($csset)) && (isset($destset))) { $set="25"; }
if((isset($acset)) && (isset($depset))) { $set="23"; }
if((isset($acset)) && (isset($destset))) { $set="24"; }
if((isset($depset)) && (isset($destset))) { $set="24"; }
if ($set="12") { if(isset($acset)) { $set="123"; } }
if ($set="13") { if(isset($depset)) { $set="124"; } }
if ($set="14") { if(isset($destset)) { $set="125"; } }
if ($set="1") { $sql = "SELECT * FROM IPS_Reports WHERE PilotID = '$pilotidset' ORDER BY StopTime DESC"; }
if ($set="2") { $sql = "SELECT * FROM IPS_Reports WHERE Callsign = 'csset' ORDER BY StopTime DESC"; }
if ($set="3") { $sql = "SELECT * FROM IPS_Reports WHERE AC = 'acset' ORDER BY StopTime DESC"; }
if ($set="4") { $sql = "SELECT * FROM IPS_Reports WHERE DepICAO = 'depset' ORDER BY StopTime DESC"; }
if ($set="5") { $sql = "SELECT * FROM IPS_Reports WHERE DesICAO = 'destset' ORDER BY StopTime DESC"; }
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$filedalt = $row["FiledAlt"];
$statusdb = $row["Status"];
$ac = $row["AC"];
$network = $row["Network"];
$starttime = $row["StartTime"];
$starttimediff = time() - $starttime;
$starttimediff = FormatTimeAgo($starttimediff, "en");
$starttime = gmdate("d-m-Y H:i:s", $starttime)."z";
$stoptime = $row["StopTime"];
$stoptimediff = time() - $stoptime;
$stoptimediff = FormatTimeAgo($stoptimediff, "en");
$stoptime = gmdate("d-m-Y H:i:s", $stoptime)."z";
$distance = $row["Distance"];
$distance = round($distance)." NM";
$duration = $row["Duration"];
$duration = FormatTime($duration);
if ($statusdb == "A") { $status="Arrived"; }
if ($statusdb == "N") { $status="Not Arrived"; }
if ($statusdb == "D") { $status="Diverted"; }
// vars uit mysql echoen
echo "<tr><td>$pilot</td><td>$depicao</td><td>$desicao</td><td>$callsign</td><td>$ac</td><td>$duration</td><td>$distance</td><td>$starttime ($starttimediff)</td><td>$stoptime ($stoptimediff)</td><td>$status</td></tr>";
}
?>
<tr style="font-weight:bold">
<td>Pilot</td><td>Dep</td><td>Des</td><td>Callsign</td><td>A/C</td><td>Duration</td><td>Distance</td><td>Start Time</td><td>Stop Time</td><td>Status</td>
</tr>
<?php
// een paar functies om tijd goed neer te zetten en te formateren
function FormatTime($minutes) {
$time = $minutes;
$hours = $time / 60;
$minutes = round(($hours - floor($hours)) * 60);
$hours = floor($hours);
if (strlen($hours) == 0) $hours = "0";
if (strlen($minutes) == 1) $minutes = "0".$minutes;
if (strlen($minutes) == 0) $minutes = "00";
$time = $hours.":".$minutes;
return $time;
}
function FormatTimeAgo($timediff, $lang) {
if ($timediff < 60)
{
if ($lang == "en") $ago = "$timediff sec";
}
elseif ($timediff < 3600)
{
$timediff2 = floor($timediff / 60);
$timediff = $timediff - ($timediff2 * 60);
if (strlen($timediff) == 1) $timediff = "0$timediff";
if ($lang == "en") $ago = "$timediff2:$timediff min";
}
else
{
$timediff2 = floor($timediff / 60);
$timediff = $timediff - ($timediff2 * 60);
if (strlen($timediff) == 1) $timediff = "0$timediff";
$timediff3 = floor($timediff2 / 60);
$timediff2 = $timediff2 - ($timediff3 * 60);
if (strlen($timediff2) == 1) $timediff2 = "0$timediff2";
if ($lang == "en") $ago = "$timediff3:$timediff2 hrs";
}
if ($lang == "en") $ago .= " ago";
return $ago;
}
// dbconnectie eraan
include("dbconnect.inc.php");
// vars halen uit een formulier
if(isset($_POST["name"])) $pilotidset=$_POST["name"];
if(isset($_POST["cs"])) $csset=$_POST["cs"];
if(isset($_POST["ac"])) $acset=$_POST["ac"];
if(isset($_POST["dep"])) $depset=$_POST["dep"];
if(isset($_POST["dest"])) $destset=$_POST["dest"];
// als de vars gezit zijn, zetten we een andere var zo dat de query daarna wordt ingesteld
if(isset($pilotidset)) { $set="1"; }
if(isset($csset)) { $set="2"; }
if(isset($acset)) { $set="3"; }
if(isset($depset)) { $set="4"; }
if(isset($destset)) { $set="5"; }
if((isset($pilotidset)) && (isset($csset))) { $set="12"; }
if((isset($pilotidset)) && (isset($acset))) { $set="13"; }
if((isset($pilotidset)) && (isset($depset))) { $set="14"; }
if((isset($pilotidset)) && (isset($destset))) { $set="15"; }
if((isset($csset)) && (isset($acset))) { $set="23"; }
if((isset($csset)) && (isset($depset))) { $set="24"; }
if((isset($csset)) && (isset($destset))) { $set="25"; }
if((isset($acset)) && (isset($depset))) { $set="23"; }
if((isset($acset)) && (isset($destset))) { $set="24"; }
if((isset($depset)) && (isset($destset))) { $set="24"; }
if ($set="12") { if(isset($acset)) { $set="123"; } }
if ($set="13") { if(isset($depset)) { $set="124"; } }
if ($set="14") { if(isset($destset)) { $set="125"; } }
if ($set="1") { $sql = "SELECT * FROM IPS_Reports WHERE PilotID = '$pilotidset' ORDER BY StopTime DESC"; }
if ($set="2") { $sql = "SELECT * FROM IPS_Reports WHERE Callsign = 'csset' ORDER BY StopTime DESC"; }
if ($set="3") { $sql = "SELECT * FROM IPS_Reports WHERE AC = 'acset' ORDER BY StopTime DESC"; }
if ($set="4") { $sql = "SELECT * FROM IPS_Reports WHERE DepICAO = 'depset' ORDER BY StopTime DESC"; }
if ($set="5") { $sql = "SELECT * FROM IPS_Reports WHERE DesICAO = 'destset' ORDER BY StopTime DESC"; }
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$filedalt = $row["FiledAlt"];
$statusdb = $row["Status"];
$ac = $row["AC"];
$network = $row["Network"];
$starttime = $row["StartTime"];
$starttimediff = time() - $starttime;
$starttimediff = FormatTimeAgo($starttimediff, "en");
$starttime = gmdate("d-m-Y H:i:s", $starttime)."z";
$stoptime = $row["StopTime"];
$stoptimediff = time() - $stoptime;
$stoptimediff = FormatTimeAgo($stoptimediff, "en");
$stoptime = gmdate("d-m-Y H:i:s", $stoptime)."z";
$distance = $row["Distance"];
$distance = round($distance)." NM";
$duration = $row["Duration"];
$duration = FormatTime($duration);
if ($statusdb == "A") { $status="Arrived"; }
if ($statusdb == "N") { $status="Not Arrived"; }
if ($statusdb == "D") { $status="Diverted"; }
// vars uit mysql echoen
echo "<tr><td>$pilot</td><td>$depicao</td><td>$desicao</td><td>$callsign</td><td>$ac</td><td>$duration</td><td>$distance</td><td>$starttime ($starttimediff)</td><td>$stoptime ($stoptimediff)</td><td>$status</td></tr>";
}
?>
Nu moet ik bij elke mogelijkheid een verschillende if isset doen, ik zou toch denken dat dit veel handiger kan, want hierdoor is dit heel veel werk en duurt het script misschien ook wel lang?
Fijn als iemand mij misschien kan helpen.
Daan
Arrays?
Ten eerste kan je de isset functie al gebruiken met:
Dus meerdere variabelen in de isset functie. Voor de rest snap ik je doel niet, misschien kun je je formulier ook even posten. En misschien een voorbeeld van de website (linkje dus) ?
Gewijzigd op 29/11/2010 20:49:29 door - Ricardo -
Dankjewel voor je snelle antwoord.
Dát zal ik zeker toepassen, hierbij het formulier, linkje komt eraan.
Hier de code, daar moeten jullie wel uitkomen toch?
Code (php)
1
2
3
4
5
6
7
8
9
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
2
3
4
5
6
7
8
9
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
<?php
include("dbconnect.inc.php");
echo '<form id="form1" name="form1" method="post" action="find.php"><p><label for="name">Name</label><select name="name" id="name">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$pilotid'>$pilot</option>";
}
echo "</select><br>";
echo '<label for="cs">Callsign</label><select name="cs" id="cs">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$callsign'>$callsign</option>";
}
echo "</select><br>";
echo '<label for="ac">Aircraft</label><select name="ac" id="ac">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$ac'>$ac</option>";
}
echo "</select><br>";
echo '<label for="dep">Departure</label><select name="dep" id="dep">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$depicao'>$depicao</option>";
}
echo "</select><br>";
echo '<label for="dest">Destination</label><select name="dest" id="dest">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$desicao'>$desicao</option>";
}
echo '</select><br><input type="submit" name="button" id="button" value="Submit" /></p></form>';
?>
include("dbconnect.inc.php");
echo '<form id="form1" name="form1" method="post" action="find.php"><p><label for="name">Name</label><select name="name" id="name">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$pilotid'>$pilot</option>";
}
echo "</select><br>";
echo '<label for="cs">Callsign</label><select name="cs" id="cs">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$callsign'>$callsign</option>";
}
echo "</select><br>";
echo '<label for="ac">Aircraft</label><select name="ac" id="ac">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$ac'>$ac</option>";
}
echo "</select><br>";
echo '<label for="dep">Departure</label><select name="dep" id="dep">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$depicao'>$depicao</option>";
}
echo "</select><br>";
echo '<label for="dest">Destination</label><select name="dest" id="dest">';
$sql = "SELECT * FROM IPS_Reports ORDER BY StopTime DESC";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$pilotid = $row["PilotID"];
$sql = "SELECT * FROM IPS_Pilots WHERE ID=$pilotid";
$row2 = mysql_fetch_array(mysql_query($sql));
$pilot = $row2["Name"];
$depicao = $row["DepICAO"];
$desicao = $row["DesICAO"];
$callsign = $row["Callsign"];
$ac = $row["AC"];
echo "<option value='$desicao'>$desicao</option>";
}
echo '</select><br><input type="submit" name="button" id="button" value="Submit" /></p></form>';
?>
Daan
Toevoeging op 29/11/2010 20:54:51:
Jordi kroon op 29/11/2010 20:47:18:
Arrays?
Sorry, arrays ken ik niet, kan je me uitleggen wat dat is?
Trouwens kan je me misschien de volgende keer iets meer vertellen dan een enkel woord?
Toevoeging op 29/11/2010 20:59:58:
Hier is het formulier: http://www.intlairways.co.cc/DPirepSys/search/search.php, die linkt naar de sql uitvoering
Heb ik gelezen, maar hoe zou ik dit in dit geval kunnen gebruiken?