如何从数据库中获取数据以获取url,然后将其放置到毕加索加载



在此处输入图像描述

这是我的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放在毕加索加载(url(我真的很困惑cz这个数据库来自WordPress默认值。蒂亚

它没有显示任何图片,因为你只是打印了URL。毕加索会尝试请求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时直接显示图像。尝试使用此方法

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

最新更新