How can I get all my data from a table in my database and show it using php?

Peter Djon

I am trying to display an array with 6 values but i don't know really how to do it. I tried to post the array with num_rows but it doesn't seem to do it. I don't know how to fix it.

<?php<br>
//four variables to connect to the database<br>
$host= "localhost";<br>
$username="root";<br>
$password='';<br>
$database="pd00255_coursework2_com1025";<br>

//create a database connection instance
$mysqli = new mysqli($host, $username, $password, $database);<br>

//if there are any values in the table, display them one at a time.
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;<br>
}<br>
echo $mysqli->host_info . "<br>";<br>

$sql = "SELECT ID, Name ,Role, Responsibilities, Age, Date of birth,     Email FROM person";<br>
$result = $mysqli->query($sql);<br>

if ($result->num_rows > 0) {<br>
// output data of each row<br>
while($row = $result->fetch_assoc()) {<br>
  echo "id: " . $row["ID"]. " - ID: " . $row["Name"]. " " . $row["Role"]. " " . $row["Responsibilities"]. "Responsibilities" . $row["Age"]. "Age" .     $row["Date of birth"]. "Date of birth" . $row["Email"]."Email" "<br>";
        }<br>
    } else {<br>
echo "0 results";<br>
}<br>
$mysqli->close;<br>
?><br>
Claudio

Your query has an error, when selecting the column Date of birth, because it has spaces, try:

"SELECT ID, Name, Role, Responsibilities, Age, `Date of birth`, Email FROM person"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how can I view the data get from database to my gridview using php?

React - how can I get updated data to show in my table?

How can I get all my values to be displayed on my table?

How can I get data from MySql using PHP in my Xcode app?

how can I get all my data from my repo with git?

How can I add and get all my database table values (numbers) and displaying the total amount? C#

How can I Count, group and show age from my database

How can I get a Value from my Database and use and show it inside an Input Field?

I want to show all my tables from my database to an API

PHP - How can I print out my database table?

How can I clone all data from my database with Symfony doctrine?

How should I get all the messages from my database and return it

How can I add the current date to my database table using php

get data from my database table

My data table not fix to page How can I show my table in whole page?

How do i display my items in a row ( using php and bootstrap to display all items from a database)

how can i delete all the records in my mysql table automatically using php?

How can I create a new table in my SQLite Database using a param from a Java String variable?

Why can't I insert all values from my HTML table into my firebase realtime database?

How can I pull user input data as type "date" into my SQL database using PHP 7?

How can I get data from my database in LINQ C#?

how can i save data, retrieved from a url into my database

How can I sync my data from an external database in Rails?

How can I print data from my database while in QTableWidget?

how can i save XmL data from a URL into my database

How can I get my table to display grouped data properly?

How can I create a table in my DB, after dropping all of my tables in database?

How can i get all my user files using Forge Data Management API?

How can I post my data that i get from SQL into divs in php