문제

I have just created a custom database table and would now like to output every inserted row from it into a predefined format using a foreach statement.

Some guidance in this matter would be great.

Thanks, Ashley

도움이 되었습니까?

해결책 3

Thanks to Rutwick Gangurde, I found out how to do it.

<?php
$mylistitems = $wpdb->get_results("SELECT * FROM wp_mytable");

foreach ( $mylistitems as $mylistitem ) 
{
echo $currency->somefield;
}
?>

다른 팁

Assuming you have table that's prefixed with the WordPress prefix (even if it's not the default one), and the table is called table. Then the following code should select everything, and allow you to go through each row. In this example, it goes through each row and outputs the content of the field foobar.

global $wpdb;
$results = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."table");
foreach ( $results as $row ) 
{
    echo $row->foobar;
};

See the Codex page on $wdpb

Use the wpdb class with something like:

global $wpdb;

$results = $wpdb->get_results("SELECT * FROM [custom table name] WHERE key = 'value'");

foreach( $results as $r ) {

    echo $r->field_name;

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top