switch gebruiken in While Loop
ik krijg de volgende error:
Parse error: syntax error, unexpected T_WHILE, expecting T_CASE or T_DEFAULT or '}' in E:\www\webroot\seo\datasource.php on line 10
het script:
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
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
<?php
$db = mysql_connect("localhost", "middelman", "*****");
mysql_select_db("middelman", $db);
$result = mysql_query("SELECT s.id, s.name, s.href, c.content FROM t_sitemap AS s, t_content AS c WHERE s.id = c.id ");
header('Content-Type: text/xml;charset=utf-8');
$base = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
switch($_GET['swfaddress']){
while($fetch_arr = mysql_fetch_array($result)){
case.$fetch_arr[href].:
echo('<h1>'.$fetch_arr[name].'</h1>');
echo('<div>'.$fetch_arr[content].'</div>');
break;
}
default:
echo('<p>Page not found.</p>');
break;
}
mysql_free_result($result);
?>
$db = mysql_connect("localhost", "middelman", "*****");
mysql_select_db("middelman", $db);
$result = mysql_query("SELECT s.id, s.name, s.href, c.content FROM t_sitemap AS s, t_content AS c WHERE s.id = c.id ");
header('Content-Type: text/xml;charset=utf-8');
$base = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
switch($_GET['swfaddress']){
while($fetch_arr = mysql_fetch_array($result)){
case.$fetch_arr[href].:
echo('<h1>'.$fetch_arr[name].'</h1>');
echo('<div>'.$fetch_arr[content].'</div>');
break;
}
default:
echo('<p>Page not found.</p>');
break;
}
mysql_free_result($result);
?>
alvast bedankt,
Gewijzigd op 01/01/1970 01:00:00 door Raymond
je moet de while niet in je switch zetten, maar de switch in je while ;)
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$db = mysql_connect("localhost", "root", "*****");
mysql_select_db("middelmanwonen", $db);
$result = mysql_query("SELECT s.id, s.name, s.href, c.content FROM t_sitemap AS s, t_content AS c WHERE s.id = c.id ");
header('Content-Type: text/xml;charset=utf-8');
$base = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
while($fetch_arr = mysql_fetch_array($result)){
switch($_GET['swfaddress']){
case $fetch_arr[href]:
echo('<h1>'.$fetch_arr[name].'</h1>');
echo('<div>'.$fetch_arr[content].'</div>');
break;
default:
echo('<p>Page not found.</p>');
break;
}
}
mysql_free_result($result);
?>
$db = mysql_connect("localhost", "root", "*****");
mysql_select_db("middelmanwonen", $db);
$result = mysql_query("SELECT s.id, s.name, s.href, c.content FROM t_sitemap AS s, t_content AS c WHERE s.id = c.id ");
header('Content-Type: text/xml;charset=utf-8');
$base = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
while($fetch_arr = mysql_fetch_array($result)){
switch($_GET['swfaddress']){
case $fetch_arr[href]:
echo('<h1>'.$fetch_arr[name].'</h1>');
echo('<div>'.$fetch_arr[content].'</div>');
break;
default:
echo('<p>Page not found.</p>');
break;
}
}
mysql_free_result($result);
?>
Gewijzigd op 01/01/1970 01:00:00 door raymond
probeer dus eens een if / else constructie.
Maar dan nog, ik zou nog niet weten waarom het niet werkt. Misschien een idee om te kijken of die query wel gelukt is? Daarna zou ik kijken of de waardes wel correct zijn geplaatst in de database (lees: identiek aan de waarde, waar het aan moet voldoen)
En werkt perfect.
Badankt voor de input.
script:
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
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
<?
header('Content-Type: text/xml;charset=utf-8');
$base = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
$db = mysql_connect("localhost", "middelman", "****");
mysql_select_db("middelman", $db);
$result = mysql_query("SELECT s.id, s.name, s.href, c.content FROM t_sitemap AS s, t_content AS c WHERE s.id = c.id ");
while($fetch_arr = mysql_fetch_array($result)){ // Overbrengen van query naar array.
$titles[$fetch_arr[href]] = $fetch_arr[name];
$contents[$fetch_arr[href]] = $fetch_arr[content];
}
mysql_free_result($result);
if($_GET['swfaddress'] != "/"){
echo($_GET['swfaddress']);
echo('<h1>'.$titles[$_GET['swfaddress']].'</h1>');
echo('<div>'.$contents[$_GET['swfaddress']].'</div>');
}
else{
echo($_GET['swfaddress']);
echo('<h1>'.$titles['/startpagina/'].'</h1>');
echo('<div>'.$contents['/startpagina/'].'</div>');
}
?>
header('Content-Type: text/xml;charset=utf-8');
$base = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'] . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
$db = mysql_connect("localhost", "middelman", "****");
mysql_select_db("middelman", $db);
$result = mysql_query("SELECT s.id, s.name, s.href, c.content FROM t_sitemap AS s, t_content AS c WHERE s.id = c.id ");
while($fetch_arr = mysql_fetch_array($result)){ // Overbrengen van query naar array.
$titles[$fetch_arr[href]] = $fetch_arr[name];
$contents[$fetch_arr[href]] = $fetch_arr[content];
}
mysql_free_result($result);
if($_GET['swfaddress'] != "/"){
echo($_GET['swfaddress']);
echo('<h1>'.$titles[$_GET['swfaddress']].'</h1>');
echo('<div>'.$contents[$_GET['swfaddress']].'</div>');
}
else{
echo($_GET['swfaddress']);
echo('<h1>'.$titles['/startpagina/'].'</h1>');
echo('<div>'.$contents['/startpagina/'].'</div>');
}
?>
Gewijzigd op 01/01/1970 01:00:00 door raymond