Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php
	include 'forms/includes/connection.php';
		
	
		$sql = "SELECT * FROM (booking_requests)";
		$query = mysqli_query ($link,$sql);
		$result = mysqli_fetch_array($query, MYSQL_ASSOC);
		
		
		if (!mysqli_query ($link,$sql)){
		die ('Error: ' . mysqli_error($link));
		} 
		else 
			
		echo implode($result);



?>


I got the records from the database to be displayed but how do it get into to display itself in the form of a table? Please Help
Posted

1 solution

You code can hardly accomplish anything. To come to PHP which is the server-side scripting, you must first have at least a good knowledge of HTML in order to build the client UI. To go further, then add CSS and JavaScript. Visit http://www.w3schools.com/[^]
Why? As you learn, you will find out that the PHP script will be the one that constructs the client UI in HTML dynamically and outputs to the browser for rendering. So how can learn PHP without knowing HTML first?
Having said that, I have prepared a sample code for you to explore at your own leisure.
PHP
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "databasename";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, fullname FROM tablename";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    // Construct table
    echo "<table border='1'><tr><th>ID</th><th>Full Name</th></tr>";

    // Output data of each row
    while($row = $result->fetch_assoc()) {

        echo "<tr><td>".$row["id"]."</td><td>". $row["fullname"]."</td></tr>";
    }
echo "</table>";
} else {
    echo "0 results";
}
$conn->close();
?>

I have drafted the code out of my mind, if there is any syntax or typo, you shall figure it too.
P.S. There are a lot of examples on the Internet that use the mysql_* extension. This has been deprecated, read http://php.net/manual/en/changelog.mysql.php[^] . Use MySQLi[^] instead.
 
Share this answer
 
v3
Comments
Ray-Rae 11-Apr-15 19:30pm    
Understood!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900