📅  最后修改于: 2023-12-03 15:17:24.494000             🧑  作者: Mango
If you're a WordPress developer looking to display database table rows in your website, you might want to consider using a WordPress plugin to handle the task. One such plugin is the List Database Table Rows plugin, which enables WordPress site owners to easily display and manipulate database tables using PHP.
The List Database Table Rows plugin offers several features, including:
Customization Options: The plugin provides flexibility in terms of customization. You can customize the HTML output of the table rows and adjust the number of rows per page.
Shortcodes Support: You can use shortcode to display the table rows on your WordPress site.
Sorting and Filtering: The plugin allows you to sort and filter table rows based on different criteria.
Here are the steps you can follow to use the List Database Table Rows plugin:
Install and activate the List Database Table Rows plugin in your WordPress site.
In the plugin settings, set up the database connection by entering your database credentials.
Create a new page or post where you want to display the table rows.
In the WordPress editor, add the shortcode [ld_table_rows]
to display all the rows in the database table. You can add attributes to the shortcode to customize the output. For example, the following shortcode [ld_table_rows table="my_table" columns="column1,column2"]
displays only the columns "column1" and "column2" from the table "my_table".
Save and publish the page or post.
To display the database table rows using PHP, you can use the following code:
<?php
//get the table rows from the database
$rows = $GLOBALS['ld_table_rows']->get_table_rows($table);
//display the table rows
echo "<table>";
foreach ($rows as $row) {
echo "<tr>";
foreach ($row as $cell) {
echo "<td>$cell</td>";
}
echo "</tr>";
}
echo "</table>";
?>
In the code above, replace $table
with the name of the database table you want to display.
Using a WordPress plugin like List Database Table Rows makes it easy for WordPress developers to display and manipulate database table rows on their website. With customization options and support for shortcodes, the plugin provides flexibility and ease of use.