WordPress.org

Ready to get started?Download WordPress

Forums

can't display data from mysql table in post (2 posts)

  1. bobster
    Member
    Posted 8 years ago #

    Hi All,

    Sorry to ask but have spend a good 5 hours working on this and no joy.

    I have set up a new table called wp_merchant_table in the wordpress database and want to pull out info from it and display in my posts.

    I have put this code into my single.php file in the hope it would get the data in the table but only get errors.
    The table has colums:
    productid - this is the product number we review
    merchant_name- eg. amazon
    country - 0 or 1
    price - err the price of the product
    affiliate_link - the link to the place to buy a product we review

    <?php
    $result = $wpdb->get_results('SELECT price, merchant_name, affiliate_link FROM wp_merchant_table WHERE productid ="25"');
    if ($result) {

    while ($row = mysql_fetch_array($result)) {
    echo $row['price'];
    echo $row['merchant_name'];
    echo $row['affiliate_link'];
    }
    }

    ?>

    I just get errors or nothing returned. Any idea why my code does not work. Alternatively if someone can tel me how to extract info from a seporate database on the same server and include into a wordpress post page that would be great also.

    Many thanks. Hope this isn't too daft a question.

    bob

  2. bobster
    Member
    Posted 8 years ago #

    Sorted it out now. Just included the code in the header.php file and seems to work out ok.

    bob

Topic Closed

This topic has been closed to new replies.

About this Topic