Hi, I'm trying to make a website in which users can post thing. The thing is, is that if it is a photo then I want it to show as a photo. Unfortunately, if the first row in the database that matches my query, all the posts will be echod out as images, which of course doesn't work. I want to run this code for each individual post. iframe works for the comments in my website, but not to check wheter it is a photo or not. So basically it doesn't check whether it is a post for the specific post-it checks if the first row is a photo or not. Code

  $posts = mysqli_query($link, "SELECT content,id, Posted_By,Date,type FROM wgo WHERE Posted_By='$channel_name' OR Posted_By='$user' ORDER BY id DESC ");

    while($row = mysqli_fetch_array($posts)) {
    $channel_name2 = $row['content'];
    $channel_name3 = $row['Posted_By'];
    $channel_name4 = $row['Date'];
    $channel_name5 = $row['id'];
    $channel_name6 = $row['type'];

    if ($channel_name6 = 'post') {
    $channel_name2 = $channel_name2;
    }
    else {
    $channel_name2 =  "<img src='/videobox/data/uploads/images/$channel_name2' height='200px' width='100px'>";
    }






echo "$channel_name2";?>

Btw I cut out some code

Not sure I understand perfectly, but in your WHILE loop you can just check if it's a picture by using some kind of post type field?
For example have a post type field that says "image|post|xyz" and then test for them in a SWITCH or something.

See, it doesn't run the code for each post.

Try the following:

 $go=true
 while($row = mysqli_fetch_array($posts)) {
    $channel_name2 = $row['content'];
    $channel_name3 = $row['Posted_By'];
    $channel_name4 = $row['Date'];
    $channel_name5 = $row['id'];
    $channel_name6 = $row['type'];
    if ($go==true) {
      if ($channel_name6 = 'post') {
          $channel_name2 = $channel_name2;
        } else {
          $channel_name2 =  "<img src='/videobox/data/uploads/images/$channel_name2' height='200px' width='100px'>";
        }
    $go=false;
    } else {
    echo $channel_name2;
    }
 }
commented: thanks for your help, but I fixed it differently :D +0

Thanks! But I fixed it by putting the code in a different place. Thanks though I appreciate it !

if ($channel_name6 = 'post') {
    $channel_name2 = $channel_name2;
} else {
    $channel_name2 =  "<img src='/videobox/data/uploads/images/$channel_name2' height='200px' width='100px'>";
}

Correct me if I'm wrong but are you not trying to see if $channel_name6 is equal to "post" and not set the value of it to "post"? If so then you need a double equals == not a single =.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.