php和mysql列出数据库并循环结果

时间:2010-04-17 04:15:25

标签: php mysql

需要初学者帮助:)

我正在做一个PHP书的例子,它列出了数据库中的表。 我在第36行收到错误:$ db list。=“$ table list”;

<?php

//connect to database
$connection = mysql_connect("localhost", "admin_cantsayno", "cantsayno")
    or die(mysql_error());

//list databases    
$dbs = @mysql_list_dbs($connection) or die(mysql_error());  

//start first bullet list
$db_list = "<ul>";
$db_num = 0;

//loop through results of functions 
while ($db_num < mysql_num_rows($dbs)) {

//get database names and make each a list point
$db_names[$db_num] = mysql_tablename($dbs, $db_num);
    $db_list .= "<li>$db_names[$db_num]";

//get table names and make another list
    $tables = @mysql_list_tables($db_names[$db_num]) or die(mysql_error());
    $table_list = "<ul>";
    $table_num = 0;

//loop through results of function  
    while ($table_num < mysql_num_rows($tables)){
    //get table names and make each bullet point
    $table_names[$table_num] = mysql_tablename($tables, $table_num);
    $table_list .= "<li>$table_names[$table_num]";
    $table_num++;
}

//close inner bullet list and increment number to continue
    $table_list .= "</ul>"
    $db_list .= "$table_list";
    $db_num++;
    }
    //close outer bullet list
    $db_list .= "</ul>";
?>

<html>
<head>
<title>MySQL Tables</title>
</head>
<body>
<p><strong>Data bases and tables on local host</strong></p>

<? echo "$db_list"; ?>

</body>

1 个答案:

答案 0 :(得分:2)

错过了分号?

    $table_list .= "</ul>" <===
    $db_list .= "$table_list";