最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get all images from this database table

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Mar 11, 2016 at 6:49 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Mar 10, 2016 at 16:54 Marin TsolovMarin Tsolov 112 bronze badges 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 – Pieter Goosen Commented Mar 10, 2016 at 17:15
  • I tried to print_r ($ res); But again no result. – Marin Tsolov Commented Mar 10, 2016 at 17:33
Add a comment  | 

2 Answers 2

Reset to default 1

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

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.

发布评论

评论列表(0)

  1. 暂无评论