dynamische lijsten met select query
Ik snap dat ik dit door middel van een class of funcie moet doen aangezen de query steeds wijzigd, echter geen idee hoe dit te implementeren.
Nu kom ik wel dynamische selectboxes tegen die een andere select beinvloeden met googelen, echter niet 1 die mijn query aanpast zodat allen datgene in de lijst komt wat ik wil.
het liefst een verwijzing naar een uitleg met voorbeeld hoe ik dit moet doen.
Misschien een leuk idee voor een tut om op phphulp te plaatsen ? Er loopt net een prijvraag voor :)
Om enigzins duidelijk te maken wat ik wil hier de pagina waaruit dit zou moeten werken :
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
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
<?php
include("../inc/listcss.php");
$host="*******"; // Host name
$username="*******"; // Mysql username
$password="********"; // Mysql password
$db_name="******"; // Database name
$tbl_name="ritten"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT *, DATE_FORMAT(Datum,'%d-%m-%Y') as ritdatum FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table border="0" cellspacing="0" cellpadding="0">
<form action="#">
<tr>
<td>select Periode
<!-- 1- 12 maanden -->
</td>
<td>select Costcenter
<select id="Costcenter">
<?
$sqlcost="SELECT Costcenter FROM bedrijven WHERE Actief='actief' ORDER BY Costcenter ";
$resultcost=mysql_query($sqlcost);
while($rowscost=mysql_fetch_array($resultcost))
{
echo "<OPTION VALUE=".$rowscost['Costcenter'].">".$rowscost['Costcenter'].
"</OPTION>";
}
?>
</select>
</td>
<td>select Rek Houder
<select id="Rehouder">
<?
$sqlcost="SELECT DISTINCT Rekhouder FROM bedrijven ORDER BY Rekhouder";
$resultcost=mysql_query($sqlcost);
while($rowscost=mysql_fetch_array($resultcost))
{
echo "<OPTION VALUE=".$rowscost['Rekhouder'].">".$rowscost['Rekhouder'].
"</OPTION>";
}
?>
</select>
</form>
</td>
</tr>
</table><br />
<table border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td align="center" width="80"><strong>Datum</strong></td>
<td align="center" width="125"><strong>Start</strong></td>
<td align="center" width="125"><strong>Eind</strong></td>
<td align="center" width="70"><strong>Bedrag</strong></td>
<td align="center" width="125"><strong>Klant</strong></td>
<td align="center" width="100"><strong>Factuur</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<? $ritID[]=$rows['ritID']; ?>
<td align="left" nowrap="nowrap"><? echo $rows['ritdatum']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Start']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Eind']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Bedrag']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Klant']; ?></td>
<td align="left" nowrap="nowrap"><input name="factuur[]" type="text" id="factuur" value="<? echo $rows['factuur']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr></form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET factuur='$factuur[$i]' WHERE ritID='$ritID[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
// header("location:factuurlijst.php");
}
mysql_close();
?>
include("../inc/listcss.php");
$host="*******"; // Host name
$username="*******"; // Mysql username
$password="********"; // Mysql password
$db_name="******"; // Database name
$tbl_name="ritten"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT *, DATE_FORMAT(Datum,'%d-%m-%Y') as ritdatum FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table border="0" cellspacing="0" cellpadding="0">
<form action="#">
<tr>
<td>select Periode
<!-- 1- 12 maanden -->
</td>
<td>select Costcenter
<select id="Costcenter">
<?
$sqlcost="SELECT Costcenter FROM bedrijven WHERE Actief='actief' ORDER BY Costcenter ";
$resultcost=mysql_query($sqlcost);
while($rowscost=mysql_fetch_array($resultcost))
{
echo "<OPTION VALUE=".$rowscost['Costcenter'].">".$rowscost['Costcenter'].
"</OPTION>";
}
?>
</select>
</td>
<td>select Rek Houder
<select id="Rehouder">
<?
$sqlcost="SELECT DISTINCT Rekhouder FROM bedrijven ORDER BY Rekhouder";
$resultcost=mysql_query($sqlcost);
while($rowscost=mysql_fetch_array($resultcost))
{
echo "<OPTION VALUE=".$rowscost['Rekhouder'].">".$rowscost['Rekhouder'].
"</OPTION>";
}
?>
</select>
</form>
</td>
</tr>
</table><br />
<table border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td align="center" width="80"><strong>Datum</strong></td>
<td align="center" width="125"><strong>Start</strong></td>
<td align="center" width="125"><strong>Eind</strong></td>
<td align="center" width="70"><strong>Bedrag</strong></td>
<td align="center" width="125"><strong>Klant</strong></td>
<td align="center" width="100"><strong>Factuur</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<? $ritID[]=$rows['ritID']; ?>
<td align="left" nowrap="nowrap"><? echo $rows['ritdatum']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Start']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Eind']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Bedrag']; ?></td>
<td align="left" nowrap="nowrap"><? echo $rows['Klant']; ?></td>
<td align="left" nowrap="nowrap"><input name="factuur[]" type="text" id="factuur" value="<? echo $rows['factuur']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr></form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET factuur='$factuur[$i]' WHERE ritID='$ritID[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
// header("location:factuurlijst.php");
}
mysql_close();
?>
$costcenter = isset ( $_POST['costcenter'] ) ? $_POST['costcenter'] : '';
$rekhouder = isset ( $_POST['rekhouder'] ) ? $_POST['rekhouder'] : '';
$where = '1=1';
if ( $periode != '' )
$where .= sprintf ( "AND periode='%s' ", $periode );
if ( $costcenter != '' )
$where .= sprintf ( "AND costcenter='%s' ", $costcenter );
if ( $rekhouder != '' )
$where .= sprintf ( "AND rekhouder='%s' ", $rekhouder );
$q = sprintf ( "SELECT foo, bar FROM bla WHERE %s", $where );