각 테이블의 첫 번째 행을 어떻게 인쇄합니까?테이블 이름을 가져와 각각의 첫 번째 행을 인쇄하십시오.
<?php
$dbname = 'mysql_database';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
echo 'Could not connect to mysql';
exit;
}
mysql_select_db($dbname);
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
//echo "<br>Table name is: {$row[0]}\n";
// Make a MySQL Connection
$tableQuery = "SELECT * FROM $dbname.$row[0] LIMIT 1";
$tableResult = mysql_query($tableQuery) or die(mysql_error());
$firstRow = mysql_fetch_array($tableResult) or die(mysql_error());
//echo $firstRow['name']. " - ". $firstRow['age']."<br>";
//how do i print field name row and first row of values
//if I don't know the field names
}
//mysql_free_result($result);
?>
이 작동하지 않는 경우에 1 행을 가져올 것인가? 대신 무엇이 인쇄됩니까? – sdleihssirhc
"데이터베이스가 선택되지 않았습니다" – sandraqu