我在国内外四小时以上投入了很多线程,似乎缺少了一件简单的事情。

我试图让多个用户将其“新闻”上传到MYSQL。
但是我只想显示已登录用户名(userpost)附加到该行的“新闻”。
$ current是可以登录的用户名。
示例A并未过滤掉不包含$ current用户的行。
示例B不提供任何输出

所以我都尝试过两个A:

$result = mysqli_query($con,"SELECT * FROM images_tbl");
//echo $current . "2" . $current;
while($row = mysqli_fetch_array($result)) {
    if ($row['userpost'] = '.$current.') {
    $num = 0;
    $num = $num + 1;
    $pic.$num = $row['images_path'];
    $h1 = $row['hlone'];


和B:

 $result = mysqli_query($con,"SELECT * FROM images_tbl WHERE (userpost = '.$current.')");
    echo $current . "2" . $current;
    while($row = mysqli_fetch_array($result)) {
      echo $row['hlone'] . " " . $row['images_path'];
      echo "<img src=\"" .$row['images_path']. "\">";
    }


27,images / 08-10-2014-1412752801.jpg(images_path),2014-10-08,Headline(hlone),Headline2,story,testb(userpost)

任何帮助将不胜感激。

最佳答案

在查询中添加where子句

//in situation A
$result = mysqli_query($con,"SELECT * FROM images_tbl where username='".$current."'");
//username is column name for user you might have to change this
while($row = mysqli_fetch_array($result)) {
    echo $row['images_path'];
    echo $row['hlone'];
}


在情况B中,请尝试此

$result = mysqli_query($con,"SELECT * FROM images_tbl WHERE userpost = '".$current."')");
    echo $current . "2" . $current;
    while($row = mysqli_fetch_array($result)) {
      echo $row['hlone'] . " " . $row['images_path'];
      echo "<img src=\"" .$row['images_path']. "\">";
    }

10-06 14:45