generating images by user id php + mysql
- by jay
function user_image($id, $increment_views = false) {
$id = mysql_real_escape_string($id);
$q = mysql_query("SELECT * FROM `images` WHERE `id` = '$id'");
if (mysql_num_rows($q)) {
$return = mysql_fetch_assoc($q);
$q = mysql_query("SELECT * FROM `sources` WHERE `source_id` = $return[id] AND `source_flagged` = 0");
while ($r = mysql_fetch_assoc($q)) {
$return['sources'][] = $r;
}
if ($increment_views) {
$q = mysql_query("UPDATE `images` SET `views` = `views` + 1 WHERE `id` = $return[id]");
}
return $return;
} else {
return false;
}
}