dongling4383 2015-06-15 13:25 采纳率: 100%
浏览 142
已采纳

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.

  • 写回答

2条回答 默认 最新

  • dongpeiwei8589 2015-06-15 13:34
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题