Meerdere Outputs
Bij het While gedeelte van men script output hij 2 keer wat hij uit het DB haalt , enig idee waarom ?
Voorbeeld: http://www.clan-design.be/aimcup/clans.php?clan=2
Code (php) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 <?phpob_start();session_start();include ("config.php");include ("includes/functions.php");if(isset($_GET[clan])){$clanid = $_GET[clan];$query = "SELECT * FROM clans WHERE clid=".$clanid."";$result = mysql_query($query); if (mysql_num_rows($result) > 0){ $data = mysql_fetch_array($result); $clid = $data[clid]; $clname = $data[clname]; $cltag = $data[cltag]; $clmirc = $data[clmirc]; $clsite = $data[clsite]; $country = $data[clcountry]; $clstatus = $data[clstatus]; $clwarning = $data[clwarning]; $clreg = $data[clreg]; $clbanned = $data[clbanned]; $clcheating = $data[clcheating]; $clwins = $data[clwins]; $clloses = $data[clloses]; $clties = $data[clties]; } echo ("$clid <br>"); echo ("$clname <br>"); echo ("$cltag <br>"); echo ("$clmirc <br>"); echo ("$clsite <br>"); country($country); echo ("<br>"); echo ("$clstatus <br>"); echo ("$clwarning <br>"); echo ("$clreg <br>"); echo ("$clbanned <br>"); echo ("$clcheating <br>"); echo ("$clwins <br>"); echo ("$clloses<br>"); echo ("$clties <br>"); $query = "SELECT * FROM users INNER JOIN clans ON users.clanid=".$clanid." ORDER BY users.id DESC "; $result= mysql_query($query); if ($result && mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $id = $row[id]; $fname = $row[fname]; $lname = $row[lname]; $user = $row[user]; $country = $row[country]; $clanrank = $row[clanrank]; $steamid = $row[steamid]; $valid = $row[valid]; if($valid == 0){ $valid = "<img src=\"images/anticheat.png\" width=\"16\" height=\"16\"/>"; } else { $valid = "<img src=\"images/anticheat.png\" width=\"16\" height=\"16\"/>"; } country($country); echo ("<a href=\"profile.php?player=$user\">$id</a>#"); echo (" $fname "); echo ("<a href=\"profile.php?player=$user\">$user</a>"); echo (" $lname "); echo ("$steamid "); clrank($clanrank); echo ("$valid <br>"); } } else{ echo ("The clan doesnt have any members !"); }}ob_end_flush();?> [/PHP][linebreak]Greets TreX
Gewijzigd op 01/01/1970 01:00:00 door TreX
Foutje?
jha in men post zie ik het php gedeelte 2 keer kweet nie waarom
Gewijzigd op 01/01/1970 01:00:00 door Jelmer -
Jelmer schreef op 31.08.2009 19:31:
Komt het niet door die INNER JOIN? Je query is wat vreemd, omdat je niet specificeert op basis van wat de rows uit clans aan de rows uit users moeten worden gekoppeld. Hoeveel clans heb je momenteel in je database zitten?
Momenteel nog maar 2 :s
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
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
<?php
ob_start();
session_start();
include ("config.php");
include ("includes/functions.php");
if (isset($_GET['clan'])) {
$clanid = $_GET['clan'];
$query = "SELECT * FROM clans WHERE clid='" . $clanid . "'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
$data = mysql_fetch_array($result);
$clid = $data['clid'];
$clname = $data['clname'];
$cltag = $data['cltag'];
$clmirc = $data['clmirc'];
$clsite = $data['clsite'];
$country = $data['clcountry'];
$clstatus = $data['clstatus'];
$clwarning = $data['clwarning'];
$clreg = $data['clreg'];
$clbanned = $data['clbanned'];
$clcheating = $data['clcheating'];
$clwins = $data['clwins'];
$clloses = $data['clloses'];
$clties = $data['clties'];
}
echo ("$clid <br>");
echo ("$clname <br>");
echo ("$cltag <br>");
echo ("$clmirc <br>");
echo ("$clsite <br>");
country($country);
echo ("<br>");
echo ("$clstatus <br>");
echo ("$clwarning <br>");
echo ("$clreg <br>");
echo ("$clbanned <br>");
echo ("$clcheating <br>");
echo ("$clwins <br>");
echo ("$clloses<br>");
echo ("$clties <br>");
$query = "SELECT * FROM users INNER JOIN clans ON users.clanid=" . $clanid . " ORDER BY users.id DESC ";
$result = mysql_query($query);
if ($result && mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$fname = $row['fname'];
$lname = $row['lname'];
$user = $row['user'];
$country = $row['country'];
$clanrank = $row['clanrank'];
$steamid = $row['steamid'];
$valid = $row['valid'];
if ($valid == 0) {
$valid = "<img src=\"images/anticheat.png\" width=\"16\" height=\"16\"/>";
} else {
$valid = "<img src=\"images/anticheat.png\" width=\"16\" height=\"16\"/>";
}
country($country);
echo ("<a href=\"profile.php?player=$user\">$id</a>#");
echo (" $fname '");
echo ("<a href=\"profile.php?player=$user\">$user</a>");
echo ("' $lname ");
echo ("$steamid ");
clrank($clanrank);
echo ("$valid <br>");
}
} else {
echo ("The clan doesnt have any members !");
}
}
ob_end_flush();
?>
ob_start();
session_start();
include ("config.php");
include ("includes/functions.php");
if (isset($_GET['clan'])) {
$clanid = $_GET['clan'];
$query = "SELECT * FROM clans WHERE clid='" . $clanid . "'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
$data = mysql_fetch_array($result);
$clid = $data['clid'];
$clname = $data['clname'];
$cltag = $data['cltag'];
$clmirc = $data['clmirc'];
$clsite = $data['clsite'];
$country = $data['clcountry'];
$clstatus = $data['clstatus'];
$clwarning = $data['clwarning'];
$clreg = $data['clreg'];
$clbanned = $data['clbanned'];
$clcheating = $data['clcheating'];
$clwins = $data['clwins'];
$clloses = $data['clloses'];
$clties = $data['clties'];
}
echo ("$clid <br>");
echo ("$clname <br>");
echo ("$cltag <br>");
echo ("$clmirc <br>");
echo ("$clsite <br>");
country($country);
echo ("<br>");
echo ("$clstatus <br>");
echo ("$clwarning <br>");
echo ("$clreg <br>");
echo ("$clbanned <br>");
echo ("$clcheating <br>");
echo ("$clwins <br>");
echo ("$clloses<br>");
echo ("$clties <br>");
$query = "SELECT * FROM users INNER JOIN clans ON users.clanid=" . $clanid . " ORDER BY users.id DESC ";
$result = mysql_query($query);
if ($result && mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$fname = $row['fname'];
$lname = $row['lname'];
$user = $row['user'];
$country = $row['country'];
$clanrank = $row['clanrank'];
$steamid = $row['steamid'];
$valid = $row['valid'];
if ($valid == 0) {
$valid = "<img src=\"images/anticheat.png\" width=\"16\" height=\"16\"/>";
} else {
$valid = "<img src=\"images/anticheat.png\" width=\"16\" height=\"16\"/>";
}
country($country);
echo ("<a href=\"profile.php?player=$user\">$id</a>#");
echo (" $fname '");
echo ("<a href=\"profile.php?player=$user\">$user</a>");
echo ("' $lname ");
echo ("$steamid ");
clrank($clanrank);
echo ("$valid <br>");
}
} else {
echo ("The clan doesnt have any members !");
}
}
ob_end_flush();
?>
Voer je query eens uit in je phpMyAdmin, dan zul je waarschijnlijk wel zien dat hij meerdere records teruggeeft. Het ligt dus aan je query, zorg dat je daar maar één record uitkrijgt (dan kun je overigens de while-loop weglaten, en maar één keer fetchen).
Verder nog:
- Haal variabelen buiten quotes;
- Gebruik enkele quotes voor echo, dubbele voor HTML;
- Let op SQL injectie;
- En gebruik een goede foutafhandeling (dan bedoel ik mét mysql_error()).
Greets :)