开发者

Getting an image url from sql database using php

I'm trying to retrieve an image url from a database called flags in the image field to use.

Where am I going wrong with this?

<?php
    connect();
    $sql = ("SELECT image FROM members, flags WHERE members.开发者_Go百科member_id = '$_SESSION[id]' AND flags.id = members.country");
    $result = mysql_query($sql);
?>
<div id="flag">
<img id="flag" src="$result" width="16px" height="11px"/>


You are using the $row variable from the last mysql_fetch, instead of $row4 in your new fetch:

 while ($row4=mysql_fetch_array($sql3)){
            $sql4 = $row4['image'];   //$row4 here instead of $row
        }

And like @halfdan commented, you don't need to use while loops when you're only dealing with one row, and you can replace those two queries with one join query


$result = mysql_query($sql); it's only to run the query you need to add one more statement which fetches the record from talbe, it could be:

  1. $result_set = mysql_fetch_object($result);
  2. $result_set = mysql_fetch_array($result);

if you are using 1 get value by $result_set->image;

if you are using 2 get value by $result_set['image'];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜