Probleempje met color switch!
Ik heb een scrip gekregen voor een overzicht neer te zetten. Alleen krijg ik niet een color switch voor elkaar op de div van regels.
Dit is wat ik normaal gebruik:
Maar nu is het overzicht door iemand anders gemaakt en krijg ik het niet voor elkaar doordat de opbouw anders is, het werkt met functions en total overzicht opbouwen:
Hoe zou ik het nu kunnen maken?
Dit is wat ik normaal gebruik:
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
$switch_style[0] = '#ffffff';
$switch_style[1] = '#edf2f9';
$style = 0;
While ($row = mysql_fetch_assoc($query))
{
$style = ($style == 0) ? 1 : 0;
echo '<div style=background-color: "'.$switch_style[$style].'"</div>';
$switch_style[1] = '#edf2f9';
$style = 0;
While ($row = mysql_fetch_assoc($query))
{
$style = ($style == 0) ? 1 : 0;
echo '<div style=background-color: "'.$switch_style[$style].'"</div>';
Maar nu is het overzicht door iemand anders gemaakt en krijg ik het niet voor elkaar doordat de opbouw anders is, het werkt met functions en total overzicht opbouwen:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
function getName($id) {
$sql = "SELECT naam
FROM
leden
WHERE id = '$id'";
//query uitvoeren
$sql_res = mysql_query($sql) or die(mysql_error());
while(list($naams)=mysql_fetch_array($sql_res))
{
$naam = $naams;
}
return $naam;
}
function buildResult($id) {
?>
<div class="items-row-box" style="background-color: <?php echo $switch_style[$style];?>">
function getName($id) {
$sql = "SELECT naam
FROM
leden
WHERE id = '$id'";
//query uitvoeren
$sql_res = mysql_query($sql) or die(mysql_error());
while(list($naams)=mysql_fetch_array($sql_res))
{
$naam = $naams;
}
return $naam;
}
function buildResult($id) {
?>
<div class="items-row-box" style="background-color: <?php echo $switch_style[$style];?>">
Hoe zou ik het nu kunnen maken?
Gewijzigd op 13/02/2014 11:43:40 door Kees Mulder
Waar zijn de html quotes?
Heb dit ook geprobeerd maar krijg ik het ook niet voor elkaar:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
function switchColor() {
$switch_style[0] = '#ffffff';
$switch_style[1] = '#edf2f9';
$style = 0;
while(list($style)=mysql_fetch_array($sql_res))
{
$style = ($style == 0) ? 1 : 0;
}
return $style;
}
function buildResult($id) {
?>
<div class="items-row-box" style="background-color: <?php echo switchColor(); ?>">
function switchColor() {
$switch_style[0] = '#ffffff';
$switch_style[1] = '#edf2f9';
$style = 0;
while(list($style)=mysql_fetch_array($sql_res))
{
$style = ($style == 0) ? 1 : 0;
}
return $style;
}
function buildResult($id) {
?>
<div class="items-row-box" style="background-color: <?php echo switchColor(); ?>">
Als je error_reporting hoger zou zetten (zodat notices opduiken) zou PHP melden dat $switch_style binnen de functie buildResult() niet bestaat.
Leesvoer: http://www.php.net/manual/en/language.variables.scope.php
Leesvoer: http://www.php.net/manual/en/language.variables.scope.php
Dus wat ik zou willen kan niet?
Volgens mij werkt je allereerste script als je daar de html quotes in zet.
Maar dan wel op de juiste plaats.
Maar dan wel op de juiste plaats.
Gewijzigd op 13/02/2014 13:00:31 door - SanThe -
Wat ik ook probeer ik krijg het niet voor elkaar in de buildResult functie...
Toevoeging op 13/02/2014 14:57:31:
Ik heb net dit nog geprobeerd maar krijg dan overal 'array' te staan:
Toevoeging op 13/02/2014 14:57:31:
Ik heb net dit nog geprobeerd maar krijg dan overal 'array' te staan:
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
function getColor()
{
$sql = "SELECT COUNT(*)
FROM leden
";
$switch_style[0] = '#ffffff';
$switch_style[1] = '#edf2f9';
$style = 0;
$sql_res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($sql_res))
{
$style = ($style == 0) ? 1 : 0;
$switch_style[$style];
return $switch_style;
}
}
function buildResult($id) {
?>
<div class="items-row-box" style="background-color: <?php echo getColor(); ?>">
function getColor()
{
$sql = "SELECT COUNT(*)
FROM leden
";
$switch_style[0] = '#ffffff';
$switch_style[1] = '#edf2f9';
$style = 0;
$sql_res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($sql_res))
{
$style = ($style == 0) ? 1 : 0;
$switch_style[$style];
return $switch_style;
}
}
function buildResult($id) {
?>
<div class="items-row-box" style="background-color: <?php echo getColor(); ?>">
Gewijzigd op 13/02/2014 15:53:34 door Kees Mulder
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
$switch_style[0] = '#ffffff';
$switch_style[1] = '#edf2f9';
$style = 0;
While ($row = mysql_fetch_assoc($query))
{
$style = ($style == 0) ? 1 : 0;
echo '<div style="background-color: '.$switch_style[$style].'"></div>';
}
$switch_style[1] = '#edf2f9';
$style = 0;
While ($row = mysql_fetch_assoc($query))
{
$style = ($style == 0) ? 1 : 0;
echo '<div style="background-color: '.$switch_style[$style].'"></div>';
}
Gewijzigd op 13/02/2014 15:55:54 door - SanThe -
Als ik dat doe, dan krijg ik bij elke regel dezelfde kleur 'edf2f9'.
Er staat nog niks in.
Ik krijg het niet werkende. Heeft het dan toch te maken dat het binnen de functie buildResult() staat?




