PHP - 打印数据库整个表

I'm trying something out in php, didn't used him a couple of years ago, so I want to start learning it quite much these days. But I don't like learning it through the books and w3school, I want to learn it through basic use of it, the most common task and such.

Well I have a question, and that would be how to use php to print the whole table inside the database.

I have made a database in my local sql server, and modified the tables through phpmyadmin. Here is how it is: Database: bookstore Table : books

In table of books I have 11 coulmns, i have a primary key assigned as book_id. I want to make my output like for every book_id all values of other columns.

example: book_id 1 title Hamlet genre Tragedy rating 9.8 very good author William Shakespeare ...

and so on.

Here is my sql SELECT inside php

<?php

$host = "localhost";
$user = "admin";
$pass ="ismarhusc1";
$db = "bookstore";

$conn = mysqli_connect($host,$user,$pass,$db) or die("Error " . mysqli_error($link)); 

$sql = "SELECT book_id, title, genre, rating, description, author, author_rating, author_description, author_id  FROM books" or die("Error in the consult.." . mysqli_error($link));
$result = mysqli_query($sql);

and now please tell me how to move forward to output this selection to page.

Try mysqli_fetch_all(), it returns all your query records.

Tip: in general you only want an associative array, you can do this by passing second argument as MYSQLI_ASSOC

Well, thanks for the heads up :)

this is the solution :

<?php

$host = "localhost";
$user = "admin";
$pass ="ismarhusc1";
$db = "bookstore";

$conn = mysqli_connect($host,$user,$pass,$db) or die("Error " . mysqli_error($link)); 


$sql = "SELECT book_id, title, genre, rating, description, author, author_rating, author_description, author_id  FROM books" or die("Error in the consult.." . mysqli_error($link));
if ($result = $conn->query($sql)) {

/* fetch associative array */
while ($row = $result->fetch_assoc()) {
    echo  $row["book_id"];
    echo ' - ' ;
    echo $row["title"];
}

/* free result set */
    $result->free();
}   
?>