简体   繁体   中英

display all data from my User table in my database

My question is how to display all data from my users table in my database? I have this.

$loop = mysql_query(“SHOW users FROM $dbname”) or die (‘cannot select tables’);

You want to SELECT the users, not SHOW them.

Basic SQL loop example:

$sql = mysql_query("SELECT * FROM `users`");

while ($row = mysql_fetch_object($sql)) {
    echo $row->id . ' ' . $row->nickname . '<br />';
}
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');    
$result = mysql_query(“SELECT * FROM Users”, $link) or die (‘cannot select tables’);

while ($row = mysql_fetch_assoc($result)) {
    echo $row['firstname'];
    echo $row['lastname'];
    echo $row['address'];
    echo $row['age'];
}

mysql_free_result($result);
$loop = mysql_query('SELECT * FROM `users`') or die();

You don't want your database name to be in the query, and you want to be using SELECT

If you haven't connected to the database earlier then you need to add this before your query:

mysql_connect($mysql_host, $mysql_user, $user_password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM