skip to Main Content

I want to display all the user account photo and name from database and put one user photo and name in a div tag and similarly with all the accounts with a link that redirect to the clicked account. But I am having problem on how to display it.If its still not clear try picturing an online shopping site where each product with its name is in its own box separately. Please help, I am actually trying to make a social networking site for my educational project. Thank You.
Heres my code:

$sql = "SELECT * FROM user WHERE NOT username = '$username'";
$account = array();
$photo1 = array();
$result = $conn->query($sql);
if($result->num_rows > 0)
{
    while($row = $result->fetch_assoc())
    {
        $account[] = $row['username'];
        $a = $row['photo'];
        $photo1[] = "<img src = '$a' alt = 'profile photo' width = '100px' height = '100px'>";
    }
}

and Heres a section of my html code: 
<div>
    <?php echo implode(', ',$photo1); ?>    
    <?php echo implode(', ',$account);?>
</div>

This is the image that I uploaded

2

Answers


  1. Could you add some wireframe for your task?

    In this way i think you need something like this:

    <div>
        <a href="$linkToUserProfile"><img src="$imgSource" alt="" title=""></a>
        <a href="$linkToUserProfile">$userName</a>
    </div>
    
    Login or Signup to reply.
  2. #try this and then add html as you need
       $sql = "SELECT * FROM user  ";
       $result = $conn->query($sql);
       if($result->num_rows > 0)
        {
          while($row = $result->fetch_assoc())
            {
              echo $row['username'];
              $a = 'www.yourdomain.com/usriamegefolder/'.$row['photo'];
              echo "<img src = '$a' alt = 'profile photo' width = '100px' height = '100px'>";
            }
         }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search