OK, I need to be clear, I am not a genius when it comes to PHP/MySQL What I do know is when I have made something more difficult than it has to be. I was wondering if someone could look at the following set of code and tell me how I can simplify it. So I know how to fix it and do it right next time.
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('fetish')) {
die('Could not select database: ' . mysql_error());
}
$userid = $this->translate($this->viewer()->getIdentity());
$result = mysql_query("SELECT photo_id FROM engine4_users WHERE user_id = $userid");
if (!$result) {
die('Could not query:' . mysql_error());
}
$photoid = mysql_result($result, 0);
$result1 = mysql_query("SELECT storage_path FROM engine4_storage_files WHERE parent_file_id = $photoid");
if (!$result1) {
die('Could not query:' . mysql_error());
}
$avatar = mysql_result($result1, 0);
if (!$avatar) {
$avatar = "application/themes/musicbox-red/images/nophoto_user_thumb_icon.png";<br>
}
$result2 = mysql_query("SELECT country FROM engine4_user_fields_search WHERE item_id = $userid");
if (!$result2) {
die('Could not query:' . mysql_error());
}
$country = mysql_result($result2, 0);
So basically what I need at the end of the day is the following Variables $userid $avatar $country
Thanks to anyone who can help in advance.
Ryan
I think this is what you need. You have to use joins. Try: