0

I want to display all rows/data from a MySQL table without knowing the column names.

I have the table name but not the column names, and I want to build a grid of the data using the table HTML attribute. I was thinking of using the schema but no idea where to start, any suggestions ?

5 Answers 5

4

SELECT * FROM table_name;

that should give you all the data including all rows.

Sign up to request clarification or add additional context in comments.

Comments

1

To get the table structure, use this SQL query:

SHOW COLUMNS FROM table_name;

From there you can then make a query that grabs all data from the table and display it as you want.

Comments

0

it may be helpful for you

$response = mysql_query('select * from table_name');
while($result = mysql_fetch_assoc($response))
{
    foreach($result as $key => $value)
    {
        echo $key.'--'.$value;
    }
}

Comments

0

This is actually an easy task to achieve with the MYSQLI_ASSOC function as it will put in the db field name as the array key. Take a look at this example:

$query = "SELECT * FROM `MyTable`";
if ($result = $mysqli->query($query)) {
    echo '<table>';
    foreach($result->fetch_all(MYSQLI_ASSOC) as $row) {
          foreach($row as $key  => $value) {
             echo '<tr><td>' . $key . '</td><td>' . $value . '</td></tr>';
         }
    }
    echo '</table>';
}

This would print all the tables key and associated values

Comments

0

On your select statement you could do "select * from table_name". Then, you go to your for loop() in php and can do more less like this:

$query = mysqli_query($your_connection_name, $your_sql_query);

Then, place a while loop:

<?php
while($row = mysqli_fetch_array($query)){

        $item_one = $row[0];
        $item_two = $row[1];
        $item_three = $row[2];

? > *//end php*

your html code here (table etc)

< ? php *//start php again*

} *//end while loop*

?> *//end php*

hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.