Masa
Masa

Reputation: 1

Select data from all tables with PHP&MySQLi

I'm trying to select all data from all tables that belong to a specific database with MySQLi.

So, I am looking for something like SELECT * FROM *

I have the following (awesome) code, but it isn't working. Can someone enlighten me?

<h1>All posts</h1>
<?php
$servername = "localhost";
$username = "Masa";
$password = "passwdhere";
$dbname = "forums";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM *";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     while($row = $result->fetch_assoc()) {
         echo '<h3>' . $row["title"] . '</h3><br><br><p>' . $row["text"] . '</p><br> <h4>Answers</h4><br><p>' . $row["answer"] .'</p><br> <form method = "post"><label for = "answer">Post your answer</label><br><textarea class = "answer" id = "answer" name = "answer" requred maxlength="10000" ></textarea><br><input type = "submit" class = "submit" name = "submit" id = "submit" value = "Answer"></form><br> <hr style="width: 650px; max-width: 100%; color: #eee;"><br><br> ';//I know, don't print HTML tags :3
     }
} else {
     echo "No posts yet! :c";
}

$conn->close();
?> 

Upvotes: 0

Views: 270

Answers (1)

patricksweeney
patricksweeney

Reputation: 4022

You want to use show tables; - that being said, I'd recommend reading the MySQL documentation or a tutorial this is really basic stuff. I'm sure just searching on SO would have given you the answer too.

Upvotes: 2

Related Questions