【问题标题】:How to get data from database to get url and then place it to Picasso load如何从数据库中获取数据以获取 url,然后将其放置到 Picasso 加载
【发布时间】:2017-02-10 08:04:58
【问题描述】:

enter image description here

这是我的 php 代码..

    <?php

if(!isset($_GET['s'])){
    $s = "Berita";
}else{
    $s = $_GET['s'];
}
if(!isset($_GET['id'])){
    header("Location: content_berita_list");
}else{
    $parent = $_GET['id'];
}

   define('DB_SERVER', 'localhost');
   define('DB_USERNAME', 'manteb_user');
   define('DB_PASSWORD', 'manteb_pass123');
   define('DB_DATABASE', 'manteb_core');
   $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);


$sql2 = "SELECT * FROM manteb_posts WHERE post_type = 'attachment' && post_parent = $parent";
$result2 = $db->query($sql2);

if ($result2->num_rows > 0) {
    // output data of each row
    while($row2 = $result2->fetch_assoc()) {
                $id = $row2['ID'];
                $type = $row2['post_type'];
        $judul = $row2['post_title'];
        $teks = $row2['post_content'];
        $date = $row2['post_date'];
        $gambar = $row2['guid'];
        $parent = $row2['post_parent'];

    }
} else {
    echo "0 results";
}
    ?>
      <html><body><?php echo $gambar; ?></body></html>

这是我的课

    public class Event implements Serializable {

    public Event(int ID, String post_title, String post_content, String guid, String post_date, String post_parent) {
        this.ID = ID;
        this.post_title = post_title;
        this.post_content = post_content;
        this.guid = guid;
        this.post_date = post_date;
        this.post_parent = post_parent;
    }

    public int ID;
    public String post_title, post_content, guid, post_date, post_parent;

}

这是我的毕加索

public static final String BASE_URL             = "http://manteb.com/";
    public static final String GAMBAR           = BASE_URL + "content_gambar_get.php?id=";


public void onBindViewHolder(EventAdapter.EventViewHolder holder, int position) {
        final Event event = eventlist.get(position);

        String fullUrl = PHPLink.GAMBAR + event.ID;

        Picasso.with(context)
                .load(fullUrl)
                .placeholder(R.drawable.mantebbw)
                .error(android.R.drawable.stat_notify_error)
                .into(holder.image_url);
        holder.txtTitle.setText(event.post_title);
        holder.txtDate.setText(event.post_date);

        holder.image_url.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in = new Intent(context, EventDetail.class);
                in.putExtra("event", event);
                in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivities(new Intent[]{in});

            }
        });
    }

我想把 $gambar 放在 Picasso 加载 (url) 我真的很困惑 cz 这个数据库来自 wordpress 默认.. tia

【问题讨论】:

  • 发生了什么错误?
  • 没有错误..它没有显示图像..我只是初学者,不知道如何从我的php中的url解析数据以放置在毕加索加载(url)..所以毕加索的这个网址变成了我的网址中的数据,就像我的帖子图片..或者这个.. manteb.com/android/content_gambar_get.php?id=2039
  • 在我的代码中它没有显示图像cz它只是显示我想要显示的图像url的url..tia..

标签: javascript java php android android-layout


【解决方案1】:

它没有显示任何图片,因为您只是打印了 URL。 Picasso 会尝试请求manteb.com/android/content_gambar.get.php?id=2039,但它得到了

<html> 
    <body>
        http://www.manteb.com/wp-content/uploads/2016/05/14edonor4_slo.jpg
    </body>
</html>

毕加索不知道如何将其转换为图像。您可以做的是在打开content_gambar.get.php 时直接显示图像。尝试使用this method

PS:当您使用生产机器时,最好删除数据库的凭据:)

【讨论】:

  • ty 这么多老兄.. 它工作正常.. 需要几天时间才能使其工作.. cz 我不擅长 php.. 呵呵..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 2011-07-16
  • 1970-01-01
  • 2021-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多