Is er een functie die als resultaat geeft hoeveel kolomen er in een tabel staan?
En ook voor hoeveel regels?
558 views
$select = "DESCRIBE `tabeletje`";
$query = mysql_query($select) or die(mysql_error());
echo $query;
<?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);
?>
Jan Koehoorn schreef op 18.06.2006 16:49Het aantal kolommen kun je vinden via mysql_num_rows ($res).
<?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";
?>
<?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";
?>