database tabel uitlezen
hallo, ik ben bezig om een beetje overzicht te krijgen in mijn muziek collectie, ik heb onderstaande al, het toevoegen werkt prima. maar ik weet alleen niet hoe je de tabel weer kan uitlezen en mooi in een tabel kan weergeven gesorteerd op alfabet.
ik hoop dat jullie hier mij een beetje kunnen helpen
wat ik al heb:
ik hoop dat jullie hier mij een beetje kunnen helpen
wat ik al heb:
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
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
<?php
//Error reporting
error_reporting(E_ALL);
//Database connectie
mysql_connect("localhost", "hardcore_test", "*********") or die (mysql_error());
mysql_select_db("hardcore_test") or die (mysql_error());
// Als er op Toevoegen is geklikt
if(isset($_POST['Submit']))
{
mysql_query("INSERT INTO muziek (artiest, naam, type, cds) VALUES ('".$_POST['artiest']."','".$_POST['naam']."','".$_POST['type']."','".$_POST['cds']."')") or die(mysql_error());
echo "<b>Succesvol toegevoed!</b><br>Klik <a href='muziek.php'>hier</a> om de lijst te bekijken.<br>";
}
?>
<h2>Toevoegen</h2>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table width="400" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="100" align="left">Artiest:</td>
<td><input name="artiest" type="text" size="40"></td>
</tr>
<tr>
<td width="100" align="left">Naam:</td>
<td><input name="naam" type="text" size="40"></td>
</tr>
<tr>
<td width="100" align="left">Type:</td>
<td><select name="type">
<option selected>Album</option>
<option>Vinyl</option>
<option>Live-set</option>
</select></td>
</tr>
<tr>
<td width="100" align="left">Aantal cd's:</td>
<td><select name="cds">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Toevoegen"></td>
</tr>
</table>
</form>
//Error reporting
error_reporting(E_ALL);
//Database connectie
mysql_connect("localhost", "hardcore_test", "*********") or die (mysql_error());
mysql_select_db("hardcore_test") or die (mysql_error());
// Als er op Toevoegen is geklikt
if(isset($_POST['Submit']))
{
mysql_query("INSERT INTO muziek (artiest, naam, type, cds) VALUES ('".$_POST['artiest']."','".$_POST['naam']."','".$_POST['type']."','".$_POST['cds']."')") or die(mysql_error());
echo "<b>Succesvol toegevoed!</b><br>Klik <a href='muziek.php'>hier</a> om de lijst te bekijken.<br>";
}
?>
<h2>Toevoegen</h2>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table width="400" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="100" align="left">Artiest:</td>
<td><input name="artiest" type="text" size="40"></td>
</tr>
<tr>
<td width="100" align="left">Naam:</td>
<td><input name="naam" type="text" size="40"></td>
</tr>
<tr>
<td width="100" align="left">Type:</td>
<td><select name="type">
<option selected>Album</option>
<option>Vinyl</option>
<option>Live-set</option>
</select></td>
</tr>
<tr>
<td width="100" align="left">Aantal cd's:</td>
<td><select name="cds">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Toevoegen"></td>
</tr>
</table>
</form>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
<?
// include je database connectie.
$sql = "SELECT * FROM tabelnaam ORDER BY iets_uit_tabel DESC";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res))
{
// echo $row['kolom1'];
// echo $row['kolom2'];
// enz enz
}
?>
// include je database connectie.
$sql = "SELECT * FROM tabelnaam ORDER BY iets_uit_tabel DESC";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res))
{
// echo $row['kolom1'];
// echo $row['kolom2'];
// enz enz
}
?>
tussen deze php code moet je zelf je html plaatsen.
Mocht het niet lukken dan hoor ik het wel :)
het lukt me nu wel om ze uit te lezen maar als ik bijv. de row artiest echo, knalt ie alle namen achter elkaar
daarom moest je er zelf nog de html inbouwen....
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?
// include je database connectie.
$sql = "SELECT * FROM tabelnaam ORDER BY iets_uit_tabel DESC";
$res = mysql_query($sql);
echo '
<table>
<tr>
';
while($row = mysql_fetch_array($res))
{
echo '
<td>'.$row['kolom1'].'</td>
<td>'.$row['kolom2'].'</td>
<td>'.$row['kolom3'].'</td>
';
}
echo '
</tr>
</table>
';
?>
// include je database connectie.
$sql = "SELECT * FROM tabelnaam ORDER BY iets_uit_tabel DESC";
$res = mysql_query($sql);
echo '
<table>
<tr>
';
while($row = mysql_fetch_array($res))
{
echo '
<td>'.$row['kolom1'].'</td>
<td>'.$row['kolom2'].'</td>
<td>'.$row['kolom3'].'</td>
';
}
echo '
</tr>
</table>
';
?>
sorry:P zat niet echt op te letten, iig bedankt!




