Gegevens uit db + benaming
Mijn bedoeling is om de gegevens uit een database in een HTML tabel te plaatsen (het is mij gelukt), maar ik weet niet hoe ik de volgende (4) namen boven deze gegevens moet krijgen (ID, Name, Level, Joined)
dit is de code:
<html>
<head>
<title>Users</title>
</head>
<body>
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
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
<?php
$db_host = "localhost";
$db_name = "directionn";
$db_pass = "";
$db = "directionn";
mysql_connect($db_host, $db_name, $db_pass);
mysql_select_db($db);
$query = "SELECT id,naam,status,datetime FROM gebruikers ORDER BY status DESC";
$result = mysql_query($query);
$column_count = mysql_num_fields($result);
echo"<table border=1>\n";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left valign=top>";
for ($column_num = 0;
$column_num < $column_count;
$column_num++)
echo "<td>$row[$column_num]</td>\n";
echo "</tr>\n";
}
?>
$db_host = "localhost";
$db_name = "directionn";
$db_pass = "";
$db = "directionn";
mysql_connect($db_host, $db_name, $db_pass);
mysql_select_db($db);
$query = "SELECT id,naam,status,datetime FROM gebruikers ORDER BY status DESC";
$result = mysql_query($query);
$column_count = mysql_num_fields($result);
echo"<table border=1>\n";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left valign=top>";
for ($column_num = 0;
$column_num < $column_count;
$column_num++)
echo "<td>$row[$column_num]</td>\n";
echo "</tr>\n";
}
?>
</body>
</html>
en dit is de link ervan:
http://directionn.di.funpic.de/recruiter.php
Bedankt :)
Ed
Gewijzigd op 25/12/2005 21:37:00 door Ed
<head>
<title>Users</title>
</head>
<body>
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
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
<?php
$db_host = "localhost";
$db_name = "directionn";
$db_pass = "marouscha2";
$db = "directionn";
mysql_connect($db_host, $db_name, $db_pass);
mysql_select_db($db);
$query = "SELECT id,naam,status,datetime FROM gebruikers ORDER BY status DESC";
$result = mysql_query($query);
$column_count = mysql_num_fields($result);
echo"<table border=1>\n";
echo"<td>ID</td><td>Name</td><td>Level</td><td>Joined</td>";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left valign=top>";
for ($column_num = 0;
$column_num < $column_count;
$column_num++)
echo "<td>$row[$column_num]</td>\n";
echo "</tr>\n";
}
?>
$db_host = "localhost";
$db_name = "directionn";
$db_pass = "marouscha2";
$db = "directionn";
mysql_connect($db_host, $db_name, $db_pass);
mysql_select_db($db);
$query = "SELECT id,naam,status,datetime FROM gebruikers ORDER BY status DESC";
$result = mysql_query($query);
$column_count = mysql_num_fields($result);
echo"<table border=1>\n";
echo"<td>ID</td><td>Name</td><td>Level</td><td>Joined</td>";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left valign=top>";
for ($column_num = 0;
$column_num < $column_count;
$column_num++)
echo "<td>$row[$column_num]</td>\n";
echo "</tr>\n";
}
?>
</body>
</html>
thnx robert :)
Ik ben ff aan het zoeken.. er was ook de mogelijkheid voor het ophalen van kolomnamen.. Dan kan je die ook automatisch in laten vullen. (mocht je dan wat willen veranderen aan de tabel, dan kan dat gemakkelijk en worden veranderingen automatisch overgenomen :)
<head>
<title>Users</title>
</head>
<body>
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
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
<?php
$db_host = "localhost";
$db_name = "directionn";
$db_pass = "marouscha2";
$db = "directionn";
mysql_connect($db_host, $db_name, $db_pass);
mysql_select_db($db);
$query = "SELECT id,naam,status,datetime FROM gebruikers ORDER BY status DESC";
$result = mysql_query($query);
$column_count = mysql_num_fields($result);
echo"<table border=1><tr>\n";
for ($column_num = 0;
$column_num < $column_count;
$column_num++){
echo"<td>echo mysql_field_name($result, $column_num)</td>";
}
echo "</tr>";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left valign=top>";
for ($column_num = 0;
$column_num < $column_count;
$column_num++){
echo "<td>$row[$column_num]</td>\n";
echo "</tr>\n";
}
?>
$db_host = "localhost";
$db_name = "directionn";
$db_pass = "marouscha2";
$db = "directionn";
mysql_connect($db_host, $db_name, $db_pass);
mysql_select_db($db);
$query = "SELECT id,naam,status,datetime FROM gebruikers ORDER BY status DESC";
$result = mysql_query($query);
$column_count = mysql_num_fields($result);
echo"<table border=1><tr>\n";
for ($column_num = 0;
$column_num < $column_count;
$column_num++){
echo"<td>echo mysql_field_name($result, $column_num)</td>";
}
echo "</tr>";
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left valign=top>";
for ($column_num = 0;
$column_num < $column_count;
$column_num++){
echo "<td>$row[$column_num]</td>\n";
echo "</tr>\n";
}
?>
</body>
</html>
Bedankt voor het zoeken :)
Graag gedaan.. En zo heb je een zo goed als universeel script voor je database ;) Je zou dit na aanpassing van de query in principe kunnen gebruiken om de gehele inhoud van een tabel netjes weer te geven op een pagina. (vraag is dan of dat nodig is, maar in dit geval kan het)