Simpele While functie
Ik heb het probleem met de volgende functie, ik heb hier een code die die uit mijn database ons assortiment haalt en deze in een tabel zet met behulp van een While loop.
Ik wil nu dat er kan worden geselecteerd hoeveel ze willen van dit product en dat deze verwerkt wordt als er op de bestel knop onderaan de pagina geklikt wordt.
Met de code die ik hieronder plaats wordt er alleen ge-echo'd hoeveel ik heb geselecteerd van het laatste product, de overige producten worden verwaarloosd.
Code:
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
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
<?php
// page text
$db = mysql_connect('localhost', 'username', 'password') or die('Error while connecting to db server');
mysql_select_db('erikkorten_awah', $db) or die('Error while selecting db');
$result = mysql_query("SELECT assortiment FROM givemetext", $db);
$result_array = mysql_fetch_row($result);
$result_integer = $result_array[ 0 ];
echo "$result_integer";
?>
<table width="630 px" border="1" bordercolor="#000000">
<p>Alcohol</p>
<tr class="row"><td>Product:</td><td>Aantal:</td><td>Prijs:</td></tr>
<?php
// tabel
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("erikkorten_awah", $db) or die("Error connecting to database");
$result = mysql_query("SELECT * FROM assortiment WHERE item_cat = 1 ORDER BY item_id", $db) or die("error querying database");
$i = $result_ar['item_id'];
$iname .= $result_ar['item_name'];
while($result_ar = mysql_fetch_assoc($result)){
?>
<tr <?php if($i%2 == 1){ echo "class='body2'"; }else{echo "class='body1'";}?>>
<td>
<?php echo $result_ar['item_name']; ?>
</td>
<td>
<?php echo $result_ar['item_quantity']; ?>
</td>
<td>
<?php echo $result_ar['item_price']; ?>
</td>
<td width="37">
<?php
echo "<form method='POST'><select name='selection' size='1'>
<option value='0'>0</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select>";
?>
</td>
</tr>
<?php
$i+=1;
}
?>
</table>
<br>
<?php $selection = $_POST['selection'];
$countselection = $selection;
?>
<input name="bestel" type="submit" value="bestel">
<?php
if(isset($_POST['bestel'])){
echo $countselection;
echo $iname;
}
?>
// page text
$db = mysql_connect('localhost', 'username', 'password') or die('Error while connecting to db server');
mysql_select_db('erikkorten_awah', $db) or die('Error while selecting db');
$result = mysql_query("SELECT assortiment FROM givemetext", $db);
$result_array = mysql_fetch_row($result);
$result_integer = $result_array[ 0 ];
echo "$result_integer";
?>
<table width="630 px" border="1" bordercolor="#000000">
<p>Alcohol</p>
<tr class="row"><td>Product:</td><td>Aantal:</td><td>Prijs:</td></tr>
<?php
// tabel
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("erikkorten_awah", $db) or die("Error connecting to database");
$result = mysql_query("SELECT * FROM assortiment WHERE item_cat = 1 ORDER BY item_id", $db) or die("error querying database");
$i = $result_ar['item_id'];
$iname .= $result_ar['item_name'];
while($result_ar = mysql_fetch_assoc($result)){
?>
<tr <?php if($i%2 == 1){ echo "class='body2'"; }else{echo "class='body1'";}?>>
<td>
<?php echo $result_ar['item_name']; ?>
</td>
<td>
<?php echo $result_ar['item_quantity']; ?>
</td>
<td>
<?php echo $result_ar['item_price']; ?>
</td>
<td width="37">
<?php
echo "<form method='POST'><select name='selection' size='1'>
<option value='0'>0</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
</select>";
?>
</td>
</tr>
<?php
$i+=1;
}
?>
</table>
<br>
<?php $selection = $_POST['selection'];
$countselection = $selection;
?>
<input name="bestel" type="submit" value="bestel">
<?php
if(isset($_POST['bestel'])){
echo $countselection;
echo $iname;
}
?>
Toevoeging op 01/04/2011 10:42:02:
Ik weet niet hoe ik de html in de code kan laten verschijnen, sorry daarvoor.
Gewijzigd op 01/04/2011 10:51:47 door Mike Hoogland
Er zijn nog geen reacties op dit bericht.