variabelen aftrekken
het lvl van het ene persoon is hoger dan het andere dus ik wil niet dat de laagste iets van de hoegere kan veranderen ik heb tot nu toe:
$lvlnumber = 2;
$lvlnumber2 = 0;
$number = $lvlnumber - $lvlnumber2;
echo $number;
maar hij geeft geen waarde trug wat is er nou fout?
Gewijzigd op 12/11/2005 15:37:00 door Han
Hoe haal je het uit de database?
while ($result=mysql_fetch_object($result))
{
$lvlnumber = $result->lvl;
}
$result2=$db->do_query("SELECT * FROM members WHERE user='".$variabele."'");
while ($result2 = mysql_fetch_object($result2))
{
$lvlnumber2=$result2->lvl;
}
en $variabele is het bersoon bij wie de user iets wil gaan veranderen
Gewijzigd op 12/11/2005 15:19:00 door Han
$result=$db->do_query(
en
$result=mysql_fetch_object(
geef één van de twee een andere naam.
Edit: Bij $result2 doe je dat ook.
Gewijzigd op 12/11/2005 15:20:00 door - SanThe -
ik heb er nu $resultaat en $resultaat2 van gemaakt maar dan werkt ie nog niet :'(
Gewijzigd op 12/11/2005 15:24:00 door Han
En waar komt die $variabele dan vandaan?
als hij op edit duwt krijgt de $variabele als waarde de naam van de user (die veranderd kan gaan worden)
Gewijzigd op 12/11/2005 15:35:00 door Han
In het veld 'user' kunnen daar dubbele namen in voorkomen? En wat zou het verschil tussen die twee queries moeten zijn?
Edit: Typo
Gewijzigd op 12/11/2005 15:40:00 door - SanThe -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>han's site</title>
<link href="http://members.lycos.nl/hanvanvenrooij/MYstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="han">
<div id="han3">
</div>
<div id="han2">
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?
include_once('lib/.db_config.php');
include_once('lib/db.php');
$db=new db($sitedb);
switch ($variable)
{
case remove:
include ("remove.php");
break;
case edit:
$result=$db->do_query("SELECT * FROM members WHERE user='".$_SESSION['user']."'");
while ($resultaat=mysql_fetch_object($result))
{
if ($resultaat->lvl == "Arnea" OR $resultaat->lvl == "Arner" OR $resultaat->lvl == "Druid of Time" OR $resultaat->lvl == "Sister of the Leaf")
{
if ($resultaat->lvl == "Arnea" OR $resultaat->lvl == "Arner")
{
$_SESSION['lvlnumber'] = "2";
}
else
{
$_SESSION['lvlnumber'] = "1";
};
$result3=$db->do_query("SELECT * FROM members WHERE user='".$variabele."'");
while ($resultaat3 = mysql_fetch_object($result3))
{
if ($resultaat3->lvl == "Arnea" OR $resultaat3->lvl == "Arner")
{
$_SESSION['lvlnumber1'] = "2";
}
else
{
if ( $resultaat3->lvl == "Druid of Time" OR $resultaat3->lvl == "Sister of the Leaf")
{
$_SESSION['lvlnumber1'] = "1";
}
else
{
$_SESSION['lvlnumber1'] = "0";
};
echo $_SESSION['lvlnumber']-$_SESSION['lvlnumber1'];
if ($_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] < "0" OR $_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] == "0")
{
echo '<br>You can\'t change the rank of a members with a higher rank!';
exit;
};
};
echo '
<form method="post" action=".memberslist.php">
<table>
<tr>
<td>
Username:
</td>
<td>
'.$resultaat3->user.'
<input type="hidden" value="'.$resultaat3->user.'" name="user">
</td>
</tr>
<tr>
<td>
Rank:
</td>
<td>';
if ($resultaat3->lvl == "Apprentice" OR $resultaat3->lvl == "Keeper of the Leaf" OR $resultaat3 == "Lady" OR $resultaat3->lvl == "Arnea")
{
echo'<input type="radio" value="Apprentice" name="lvl">Apprentice<br>
<input type="radio" value="Lady" name="lvl">Lady<br>
<input type="radio" value="Sister of the Leaf" name="lvl">Sister of the Leaf<br>';
echo'<input type="radio" value="Arnea" name="lvl">Arnea<br>';
}
else
{
echo'<input type="radio" value="Recruit" name="lvl">Recruit<br>
<input type="radio" value="Lord" name="lvl">Lord<br>
<input type="radio" value="Druid of Time" name="lvl">Druid of Time<br>';
echo'<input type="radio" value="Arner" name="lvl">Arner<br>';
};
echo'
</td>
</tr>
<tr>
<td>
<input type="submit" name="edit" value="Edit" />
</td>
</tr>
</table>
</form>';
};
}
else
{
echo 'You\'re not authorised to visit this page';
};
break;
};
};
if (!empty($_SESSION['user']))
{
$user = $_SESSION['user'];
$result=$db->do_query("SELECT * FROM members WHERE user='".$_SESSION['user']."'");
while ($result=mysql_fetch_object($result))
{
$result2=$db->do_query("SELECT * FROM members ORDER BY user");
echo '<table>
<tr>
<td width="100">
<b>Username</b>
</td>
<td width="100">
<b>Rank</b>
</td>';
if ($result->lvl == "Arner" OR $result->lvl == "Arnea" OR $result->lvl == "Druid of Time" OR $result->lvl == "Sister of the Leaf")
{
echo'
<td width="200">
<b>Action </b>
</td>
</tr>';
};
while ($resultaat2 =mysql_fetch_object($result2))
{
echo '<tr>
<td>
<a href="http://members.lycos.nl/hanvanvenrooij/profile.php?variable='.$resultaat2->user.'">'.$resultaat2->user.'</a>
</td>
<td>
'.$resultaat2->lvl.'
</td>';
if ( $result->lvl == "Arnea" OR $result->lvl == "Arner" OR $result->lvl == "Druid of Time" OR $result->lvl == "Sister of the Leaf" )
{
if ($resultaat2->user == $result->user)
{
echo '<td>
You can\'t edit your own profile.
</td>
</tr>';
}
else
{
echo'
<td>
<a href="http://members.lycos.nl/hanvanvenrooij/memberlist.php?variabele='.$resultaat2->user.'&variable=remove">Remove</a>
<a href="http://members.lycos.nl/hanvanvenrooij/memberlist.php?variabele='.$resultaat2->user.'&variable=edit">Edit</a>
</tr>';
};
};
};
echo '</table><br><br><br>';
};
}
else
{
echo 'You\'ll have to log in to visit this page.';
};
?>
include_once('lib/.db_config.php');
include_once('lib/db.php');
$db=new db($sitedb);
switch ($variable)
{
case remove:
include ("remove.php");
break;
case edit:
$result=$db->do_query("SELECT * FROM members WHERE user='".$_SESSION['user']."'");
while ($resultaat=mysql_fetch_object($result))
{
if ($resultaat->lvl == "Arnea" OR $resultaat->lvl == "Arner" OR $resultaat->lvl == "Druid of Time" OR $resultaat->lvl == "Sister of the Leaf")
{
if ($resultaat->lvl == "Arnea" OR $resultaat->lvl == "Arner")
{
$_SESSION['lvlnumber'] = "2";
}
else
{
$_SESSION['lvlnumber'] = "1";
};
$result3=$db->do_query("SELECT * FROM members WHERE user='".$variabele."'");
while ($resultaat3 = mysql_fetch_object($result3))
{
if ($resultaat3->lvl == "Arnea" OR $resultaat3->lvl == "Arner")
{
$_SESSION['lvlnumber1'] = "2";
}
else
{
if ( $resultaat3->lvl == "Druid of Time" OR $resultaat3->lvl == "Sister of the Leaf")
{
$_SESSION['lvlnumber1'] = "1";
}
else
{
$_SESSION['lvlnumber1'] = "0";
};
echo $_SESSION['lvlnumber']-$_SESSION['lvlnumber1'];
if ($_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] < "0" OR $_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] == "0")
{
echo '<br>You can\'t change the rank of a members with a higher rank!';
exit;
};
};
echo '
<form method="post" action=".memberslist.php">
<table>
<tr>
<td>
Username:
</td>
<td>
'.$resultaat3->user.'
<input type="hidden" value="'.$resultaat3->user.'" name="user">
</td>
</tr>
<tr>
<td>
Rank:
</td>
<td>';
if ($resultaat3->lvl == "Apprentice" OR $resultaat3->lvl == "Keeper of the Leaf" OR $resultaat3 == "Lady" OR $resultaat3->lvl == "Arnea")
{
echo'<input type="radio" value="Apprentice" name="lvl">Apprentice<br>
<input type="radio" value="Lady" name="lvl">Lady<br>
<input type="radio" value="Sister of the Leaf" name="lvl">Sister of the Leaf<br>';
echo'<input type="radio" value="Arnea" name="lvl">Arnea<br>';
}
else
{
echo'<input type="radio" value="Recruit" name="lvl">Recruit<br>
<input type="radio" value="Lord" name="lvl">Lord<br>
<input type="radio" value="Druid of Time" name="lvl">Druid of Time<br>';
echo'<input type="radio" value="Arner" name="lvl">Arner<br>';
};
echo'
</td>
</tr>
<tr>
<td>
<input type="submit" name="edit" value="Edit" />
</td>
</tr>
</table>
</form>';
};
}
else
{
echo 'You\'re not authorised to visit this page';
};
break;
};
};
if (!empty($_SESSION['user']))
{
$user = $_SESSION['user'];
$result=$db->do_query("SELECT * FROM members WHERE user='".$_SESSION['user']."'");
while ($result=mysql_fetch_object($result))
{
$result2=$db->do_query("SELECT * FROM members ORDER BY user");
echo '<table>
<tr>
<td width="100">
<b>Username</b>
</td>
<td width="100">
<b>Rank</b>
</td>';
if ($result->lvl == "Arner" OR $result->lvl == "Arnea" OR $result->lvl == "Druid of Time" OR $result->lvl == "Sister of the Leaf")
{
echo'
<td width="200">
<b>Action </b>
</td>
</tr>';
};
while ($resultaat2 =mysql_fetch_object($result2))
{
echo '<tr>
<td>
<a href="http://members.lycos.nl/hanvanvenrooij/profile.php?variable='.$resultaat2->user.'">'.$resultaat2->user.'</a>
</td>
<td>
'.$resultaat2->lvl.'
</td>';
if ( $result->lvl == "Arnea" OR $result->lvl == "Arner" OR $result->lvl == "Druid of Time" OR $result->lvl == "Sister of the Leaf" )
{
if ($resultaat2->user == $result->user)
{
echo '<td>
You can\'t edit your own profile.
</td>
</tr>';
}
else
{
echo'
<td>
<a href="http://members.lycos.nl/hanvanvenrooij/memberlist.php?variabele='.$resultaat2->user.'&variable=remove">Remove</a>
<a href="http://members.lycos.nl/hanvanvenrooij/memberlist.php?variabele='.$resultaat2->user.'&variable=edit">Edit</a>
</tr>';
};
};
};
echo '</table><br><br><br>';
};
}
else
{
echo 'You\'ll have to log in to visit this page.';
};
?>
</div>
</div>
</body>
</html>
SanThe:
Ik snap er niks meer van.
In het veld 'user' kunnen daar dubbele namen in voorkomen? En wat zou het verschil tussen die twee queries moeten zijn?
In het veld 'user' kunnen daar dubbele namen in voorkomen? En wat zou het verschil tussen die twee queries moeten zijn?
Zelfde vragen. Ik begrijp van dat script niks. Er komt onder andere een $variabele in voor die nergens wordt gedefiniëerd.
$result3=$db->do_query("SELECT * FROM members WHERE user='".$variabele."'");
Het level van de ingelogde user wordt gezocht met deze query:
$result=$db->do_query("SELECT * FROM members WHERE user='".$_SESSION['user']."'");
($_SESSION['user'] is de sessie die ik aanmaak als iemand zich inlogd
$resultaat->lvl en $resultaat3-> worden omgezet in getallen:
recruit apprentice Lord en Lady worden 0
Druid of time en sister of the leaf worden 1
Arner en Arnea worden 2
die worden dan met elkaar vergeleken door:
if ($_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] < "0" OR $_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] == "0")
als ze kleiner of gelijk zijn dan 0 krijg je de foutmelding dat je t niet mag veranderen
ik hoop dat dit hielp
Om te beginnen moet je die $variabele dus uit de url ophalen met $_GET['variabele'] en voor de rest moet ik even meer tijd hebben.
volgens mij trekt ie altijd alleen maar string uit de db.
ik heb de if ($_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] < "0" OR $_SESSION['lvlnumber'] - $_SESSION['lvlnumber1'] == "0")
in het else deel van een andere if gedaan dus lukte het niet echt sry niet slaan ik weet dat dit er nu al heel erg dom uit ziet