-1

i am trying to call some data from my wordpress db

its custom form in wordpress and i failed to get data from database and print it in my html part

my code is

<?php
        global $wpdb;
        $result = $wpdb->get_results( "SELECT * FROM wp_pen" );
        if(!empty($result)) :
        foreach((array)$result as $row) : 
        ?>
    <div class="list">
        <p class="list-time">
           <i class="fa fa-flag" aria-hidden="true"></i>
            <?php echo $row['time']; ?>
        </p>
        <table class="ta1">
            <tbody>
                    <tr>
                        <td width="10%" align="center">
                        <img src="images/avatar/avatar.png">
                        </td>
                        <td width="45%" align="center">
                            الاسم:<span><?php echo $row['user']; ?></span>
                        </td>
                        <td width="45%" align="center">
                            الدولة:<span><?php echo $row['con']; ?></span>
                        </td>
                    </tr>
            </tbody>
        </table>
        <table class="ta2">
            <tbody>
                <tr align="center"><td><span><?php echo $row['comment']; ?></span></td></tr>
                <tr>
                    <td align="center">
                    <br>
                        <a target="_blank" href="#" class="pin">Pin:<?php echo $row['pen']; ?></a>

                    </td>  
                </tr>
            </tbody>
        </table>
    </div>
        <?php
        endforeach;
        endif;
        ?>

i wanna to know how i get and echo data from db

Wael Mahmoud
  • 376
  • 2
  • 9
  • thanks i got answer by change this $row['user'] by $row->user <[Here](https://stackoverflow.com/questions/16589313/php-error-cannot-use-object-of-type-stdclass-as-array-array-and-object-issues) – Wael Mahmoud Nov 21 '17 at 17:38

2 Answers2

0

Variable with database data on line 3 is $result.

In foreach you try to read $results.

foreach((array)$result as $row) : 
pavel
  • 26,538
  • 10
  • 45
  • 61
  • my mistake in line 3 just here by wrong i get this error Fatal error: Cannot use object of type stdClass as array in line 105 – Wael Mahmoud Nov 21 '17 at 17:25
  • resolved >> https://stackoverflow.com/questions/16589313/php-error-cannot-use-object-of-type-stdclass-as-array-array-and-object-issues – Wael Mahmoud Nov 21 '17 at 17:39
0

I'm not sure I understand the question, but if I do...

One option is to query the wp database just like any other database and then echo out, for example:

$result = mysql_query("SELECT post_excerpt FROM wp_posts WHERE id = '231'");
echo $result;

James Hawkins
  • 218
  • 2
  • 11