Well, I guess the name is not the best title, but let me explain my problem: I am creating a website on which I want people to post (anyway), and I have to show their gravatar profile profile, so this is what I did :
<?php
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = 'https://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
require("db.php");
$sql = "SELECT * FROM posts ORDER BY date DESC";
foreach ($db->query($sql) as $row) {
$user = $row['user_id'];
$sql_user = "SELECT email FROM users WHERE id = $user";
foreach ($db->$sql_user as $row_user) {
var_dump($row_user);
echo "<img src=\"".get_gravatar($row_user['email'])."\"/>";
}
echo "<h2>".$row['title']."</h2><br/>";
echo "<p>".$row['content']."</p><br/>";
}
But it doesn’t work (well, it works, but it doesn’t show me the user profile picture, only the message). So, I think the problem is that I cannot call the variable twice $db, but I'm not sure, so m = why I ask if there is a way to fix my problem or select 2 tables at the same time.
source
share