-2

I'm having a hard time concatenating with quotation within a quotation this question might not be useful to anyone but I really need this to work.

Here's the code and I want this to work properly but it seems like i'm making a mistake somewhere.

$query = "SELECT message,time,user_id FROM post ORDER BY time DESC";
                $query_run = mysqli_query($con,$query);
                while($row = mysqli_fetch_assoc($query_run))
                {
                    $message = $row['message'];
                    $user_id = $row['user_id'];
                    echo "<img src= 'https://graph.facebook.com/'.'$user_id'.'/picture?width=50&height=40' class = 'post_dp'>";

                }

I don't know how can concatenate user_id with the link.

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
monkey coder
  • 153
  • 1
  • 1
  • 11

2 Answers2

1
$query = "SELECT message,time,user_id FROM post ORDER BY time DESC";
            $query_run = mysqli_query($con,$query);
            while($row = mysqli_fetch_assoc($query_run))
            {
                $message = $row['message'];
                $user_id = $row['user_id'];
                echo "<img src= 'https://graph.facebook.com/". $user_id ."/picture?width=50&height=40' class = 'post_dp'>";

            }
kRiZ
  • 2,320
  • 4
  • 28
  • 39
1

If you start a string with a double quote you have to end it with a double quote.

echo "<img src= 'https://graph.facebook.com/".'$user_id'."/picture?width=50&height=40' class = 'post_dp'>";

But, as php double quotes can translate variables you don't need to close them and reopen at all:

echo "<img src= 'https://graph.facebook.com/$user_id/picture?width=50&height=40' class = 'post_dp'>";
emiliopedrollo
  • 910
  • 6
  • 21