kolomen in tabel
En ook voor hoeveel regels?
$query = mysql_query("SELECT id FROM tabel");
$aantal_regels = mysql_num_rows($query);
Voor de kolommen zou ik moeten zoeken..
Waar zou ik eventueel moeten zoeken (zoekwoord ed)
gewoon DESCRIBE tabel
Code (php)
1
2
3
2
3
$select = "DESCRIBE `tabeletje`";
$query = mysql_query($select) or die(mysql_error());
echo $query;
$query = mysql_query($select) or die(mysql_error());
echo $query;
komt:
Resource id #4
Geen worder ;) Doe even mysql_fetch_assoc();
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
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
<?php
$conn = mysql_connect("localhost", "**", "**");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("kot")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT *
FROM kot_msnlijst
";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
echo $row["voornaam"];
echo $row["achternaam"];
}
mysql_free_result($result);
?>
$conn = mysql_connect("localhost", "**", "**");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("kot")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT *
FROM kot_msnlijst
";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
echo $row["voornaam"];
echo $row["achternaam"];
}
mysql_free_result($result);
?>
komt alleen de inhoud uit, ik wil graag het aantal kolommen
Zie voorbeeldcode van aka!
Het aantal kolommen kun je vinden via mysql_num_rows ($res).
Jan:
Het aantal kolommen kun je vinden via mysql_num_rows ($res).
ALS je je query $res hebt genoemd ;-) :p
mysql_num_fields() is voor het aantal kolommen
Code1 (kolommen):
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
$link = mysql_connect("localhost", "gebruiker", "wachtwoord");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM tabel", $link);
$num_rows = mysql_num_fields($result);
echo "$num_rows columns\n";
?>
$link = mysql_connect("localhost", "gebruiker", "wachtwoord");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM tabel", $link);
$num_rows = mysql_num_fields($result);
echo "$num_rows columns\n";
?>
Code2 (Regels):
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
$link = mysql_connect("localhost", "gebruiker", "wachtwoord");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM tabel", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows\n";
?>
$link = mysql_connect("localhost", "gebruiker", "wachtwoord");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM tabel", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows\n";
?>
De code werkt bij mij, bedankt allemaal!
die kolommen heb ik gemaakt met jullie hulp