1

This is my code. Where I'm wrong?

<?php
    $connection = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD); 
    mysql_select_db($DB_NAME);
    $img = mysql_query("SELECT * FROM wp_bwg_image");

    while($res = mysql_fetch_array($img)){
        echo $res;
    }
?>

From this table I want to take any pictures.

enter image description here

3
  • $res is probably an object or array, try print_r($res); or var_dump($res); to see what if anything you are ending up with.
    – majick
    Commented Mar 10, 2016 at 17:09
  • 3
    The mysql_ extensions has been depreciated in PHP 5.5 and is now removed in PHP 7. See this Commented Mar 10, 2016 at 17:15
  • I tried to print_r ($ res); But again no result. Commented Mar 10, 2016 at 17:33

2 Answers 2

1

Use the global $wpdb for example $myrows = $wpdb->get_results( “insert sql here");

0

Try this:

<?php
    $connection = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD); 
    mysql_select_db($DB_NAME);
    $img = mysql_query("SELECT * FROM wp_bwg_image");

    while($res = mysql_fetch_array($img)){
        $Image = $res['image_url'];
        echo $Image;
    }
?>

You are not declaring the row name from which you want to get data.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.