开发者

php and mysql listing databases and looping through results [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

Beginner help needed :)

I am doign an example form a php book which lists tables in databases. I am getting an error on line 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>


missed semicolon?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜