Problemen met array weergeven in dynamic table
Beste phpers,
Ik ben vrij nieuw met php en zou graag wat uitleg willen hebben over het volgende:
Ik heb een 2 php pagina's. De één met dynamische checkboxen "ID[]" en de andere met het statement "select".
Nu is het de bedoeling dat ik op de eerste pagina de checkboxen kan aanvinken (dus de id's) en op de andere pagina moet dan het "select statement" te zien zijn.
Dit lukt allemaal aardig, alleen wil ik het resultaat in een tabel zetten en dit wilt niet helemaal lukken. Ik heb het nu namelijk zo dat het resultaat klopt, maar dat de tabel met het resultaat erin net zo vaak voorkomt als het resultaat zelf.
Ik denk dat het wat met mijn foreach loop te maken heeft.
Dit is de code op mijn eerste pagina:
{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
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
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_My_Connection_CD, $My_Connection_CD);
$query_Recordset1 = "SELECT ID FROM sheet1";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $My_Connection_CD) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_My_Connection_CD, $My_Connection_CD);
$query_Recordset1 = "SELECT ID FROM sheet1";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $My_Connection_CD) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="result.php">
<p>
<label for="ID[]"></label>
<input name="ID[]" type="checkbox" id="ID[]" value="" />
<label for="ID[]"></label>
<label for="ID[]"></label>
<br />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
</p>
</form>
</body>
</html>
{/code}
En dit is de code van mijn resultpagina:
{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
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
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
foreach($_GET["ID"] as $val) {
$_GET['wissen'] = $val;
if ((isset($_GET['wissen'])) && ($_GET['wissen'] != "")) {
mysql_select_db($database_My_Connection_CD, $My_Connection_CD);
$query_Recordset1 = sprintf("SELECT ID, SONGS FROM sheet1 WHERE ID = %s", GetSQLValueString ($_GET['wissen'], "int"));
}
$Recordset1 = mysql_query($query_Recordset1, $My_Connection_CD) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
foreach($_GET["ID"] as $val) {
$_GET['wissen'] = $val;
if ((isset($_GET['wissen'])) && ($_GET['wissen'] != "")) {
mysql_select_db($database_My_Connection_CD, $My_Connection_CD);
$query_Recordset1 = sprintf("SELECT ID, SONGS FROM sheet1 WHERE ID = %s", GetSQLValueString ($_GET['wissen'], "int"));
}
$Recordset1 = mysql_query($query_Recordset1, $My_Connection_CD) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<br />
</body>
</html>
{/code}
Gewijzigd op 15/10/2010 18:10:58 door Armando Armanio
Post relevante code erbij, dan is het verhaal veel duidelijker en kunnen we je gelijk ook de juiste hoek in trappen.
Ik weet niet hoe ik de code erbij kan zetten????? Is het gewoon in dit veld plakken??
{/code} om je code heen
de {} moet je wel lezen als []
zie:
http://www.phphulp.nl/veel-gestelde-vragen/#bbcode
Toevoeging op 15/10/2010 18:15:54:
En nu nog op de juiste manier, want zoals het er nu staat is het niet te lezen
zie:
http://www.phphulp.nl/veel-gestelde-vragen/#bbcode
In principe wel inclusief de {code}de {} moet je wel lezen als []
zie:
http://www.phphulp.nl/veel-gestelde-vragen/#bbcode
Toevoeging op 15/10/2010 18:15:54:
En nu nog op de juiste manier, want zoals het er nu staat is het niet te lezen
zie:
http://www.phphulp.nl/veel-gestelde-vragen/#bbcode
Gewijzigd op 15/10/2010 18:08:38 door Noppes Homeland
http://www.phphulp.nl/veel-gestelde-vragen/#bbcode gelezen maar gerijp niet hoe ik mijn code op de juiste manier hier neer moet zetten?????