php in html toevoegen
Ik heb een scriptje wat een aantal variabelen oproep in een sql database:
Code (php)
1
$data = mysql_query("SELECT username, score FROM Munzee WHERE username='name2' OR username='name1' OR username='name5' OR username='name4' OR username='name3' LIMIT 5")
Deze wil ik graag invoegen in een html pagina:
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
<!-- top players Box #1 -->
<div class="productbox">
<div class="topproduct"></div>
<div class="headingproduct">
<div class="title">
<h4>TOP SPELERS</h4>
</div>
<div class="price"></div>
<div class="description"></div>
</div>
<div class="contentproduct">
<ul class="productfeatures">
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
</ul>
<div class="clear"></div>
<div class="buttoncenter"></div>
<div class="clear"></div>
</div>
<div class="bottomproduct"></div>
</div>
<!-- top players box #1 End -->
<div class="productbox">
<div class="topproduct"></div>
<div class="headingproduct">
<div class="title">
<h4>TOP SPELERS</h4>
</div>
<div class="price"></div>
<div class="description"></div>
</div>
<div class="contentproduct">
<ul class="productfeatures">
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
</ul>
<div class="clear"></div>
<div class="buttoncenter"></div>
<div class="clear"></div>
</div>
<div class="bottomproduct"></div>
</div>
<!-- top players box #1 End -->
Weten jullie hoe ik dat netjes kan oplossen ?
Thanks!
Patrick
dit heb ik geprobeerd en ik krijg geen output te zien?
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?
while($row = mysql_fetch_assoc($query)){
$username = $row['username'];
}
echo $username;
?>
while($row = mysql_fetch_assoc($query)){
$username = $row['username'];
}
echo $username;
?>
Daar wel?
dit is de complete stats.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
// Connects to your Database
include("config.php");
$connection = mysql_connect("$host", "$username", "$password") or die ("Unable to connect to server");
mysql_select_db("lupux_munzee") or die(mysql_error());
$data = mysql_query("SELECT username, score FROM Munzee WHERE username='robje64' OR username='hansbudel' OR username='hatti' OR username='aventurijn' OR username='flet' LIMIT 5")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Username:</th> <td>".$info['username'] . "</td> ";
Print "<th>Score:</th> <td>".$info['score'] . " </td></tr>";
}
Print "</table>";
?>
// Connects to your Database
include("config.php");
$connection = mysql_connect("$host", "$username", "$password") or die ("Unable to connect to server");
mysql_select_db("lupux_munzee") or die(mysql_error());
$data = mysql_query("SELECT username, score FROM Munzee WHERE username='robje64' OR username='hansbudel' OR username='hatti' OR username='aventurijn' OR username='flet' LIMIT 5")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Username:</th> <td>".$info['username'] . "</td> ";
Print "<th>Score:</th> <td>".$info['score'] . " </td></tr>";
}
Print "</table>";
?>
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
// Connects to your Database
include("config.php");
$connection = mysql_connect($host, $username, $password);
mysql_select_db("lupux_munzee");
$data = mysql_query("SELECT username, score FROM Munzee WHERE username='robje64' OR username='hansbudel' OR username='hatti' OR username='aventurijn' OR username='flet' LIMIT 5");
if($data === false){
echo mysql_error();
}
elseif(mysql_num_rows($data) > 0){
echo "<table border cellpadding=3>";
while($info = mysql_fetch_assoc( $data )){
echo "
<tr>
<th>Username:</th> <td>".$info['username'] . "</td>
<th>Score:</th> <td>".$info['score'] . " </td>
</tr>";
}
}
echo "</table>";
?>
// Connects to your Database
include("config.php");
$connection = mysql_connect($host, $username, $password);
mysql_select_db("lupux_munzee");
$data = mysql_query("SELECT username, score FROM Munzee WHERE username='robje64' OR username='hansbudel' OR username='hatti' OR username='aventurijn' OR username='flet' LIMIT 5");
if($data === false){
echo mysql_error();
}
elseif(mysql_num_rows($data) > 0){
echo "<table border cellpadding=3>";
while($info = mysql_fetch_assoc( $data )){
echo "
<tr>
<th>Username:</th> <td>".$info['username'] . "</td>
<th>Score:</th> <td>".$info['score'] . " </td>
</tr>";
}
}
echo "</table>";
?>
Gewijzigd op 29/03/2012 11:12:44 door gerhard l
de stats.php pagina werkt, maar daar is nog geen layout.
als ik de code invoer in de html pagina zie ik niets...
Met bovenstaande code krijg ik een error:
Parse error: syntax error, unexpected $end in/ online 20
Toevoeging op 29/03/2012 11:23:42:
ik zie al wat er fout was in de code, er miste een } op regel 20
die is nu opgelost, nu nog in de html :-)
Toevoeging op 29/03/2012 11:47:38:
Je was met net voor zag ik :-)
Thanks
Alleen krijg ik geen output te zien via html.
Iemand een idee ?
Toevoeging op 29/03/2012 12:14:30:
is het misschien ook mogelijk om de output van het script (de beste 5 zeg maar)
weer te geven in deze tabel:
Code (php)
1
2
3
4
5
2
3
4
5
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
misschien met een
Toevoeging op 29/03/2012 12:59:56:
het volgende heb ik gedaan, helaas nog steeds geen output
in de body van de stats.html pagina heb ik gezet:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
include("config.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db("lupux_munzee") or die( "Unable to select database");
$query="SELECT * FROM Munzee";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
include("config.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db("lupux_munzee") or die( "Unable to select database");
$query="SELECT * FROM Munzee";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
Daarna in de bos waar de output moet komen heb ik de volgende code gezet:
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
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
<!-- top players Box #1 -->
<div class="productbox">
<div class="topproduct"></div>
<div class="headingproduct">
<div class="title">
<h4>TOP SPELERS</h4>
</div>
<div class="price"></div>
<div class="description"></div>
</div>
<div class="contentproduct">
<ul class="productfeatures">
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"username");
$f2=mysql_result($result,$i,"field2");
$f3=mysql_result($result,$i,"field3");
$f4=mysql_result($result,$i,"field4");
$f5=mysql_result($result,$i,"field5");
?>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/><?php echo $f1; ?></li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
</ul>
<div class="clear"></div>
<div class="buttoncenter"></div>
<div class="clear"></div>
</div>
<div class="bottomproduct"></div>
</div>
<!-- top players box #1 End -->
<div class="productbox">
<div class="topproduct"></div>
<div class="headingproduct">
<div class="title">
<h4>TOP SPELERS</h4>
</div>
<div class="price"></div>
<div class="description"></div>
</div>
<div class="contentproduct">
<ul class="productfeatures">
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"username");
$f2=mysql_result($result,$i,"field2");
$f3=mysql_result($result,$i,"field3");
$f4=mysql_result($result,$i,"field4");
$f5=mysql_result($result,$i,"field5");
?>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/><?php echo $f1; ?></li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
<li><img src="images/features-icon1.png" alt="" class="product-icon"/>Speler 1</li>
</ul>
<div class="clear"></div>
<div class="buttoncenter"></div>
<div class="clear"></div>
</div>
<div class="bottomproduct"></div>
</div>
<!-- top players box #1 End -->
een paar keer getest maar ik krijg niets in beeld.
Wie weet wat er fout gaat ?
Thanks!