Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7732235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:40:53+00:00 2026-06-01T06:40:53+00:00

OK, I need to be clear, I am not a genius when it comes

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:40:54+00:00Added an answer on June 1, 2026 at 6:40 am

    I think this is what you need. You have to use joins. Try:

    $userid = $this->translate($this->viewer()->getIdentity());
    $result = mysql_query("
    SELECT u.user_id, f.country as `country`, s.storage_path as `spath` FROM engine4_users as u
    LEFT JOIN engine4_storage_files as s ON u.photo_id = s.parent_file_id 
    JOIN engine4_user_fields_search as f ON u.user_id = f.item_id
    WHERE u.user_id = $userid
    ");
    while($row = mysql_fetch_array($result)) {
      // Do your code logic here
      $country = $row['country'];
      if($row['spath']) {
        $avatar = "application/themes/musicbox-red/images/nophoto_user_thumb_icon.png";
      }
      else
        $avatar = NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read something about this on PHP docs , but it's not clear to
I know similar questions have been asked before, but still things are not clear
It's not clear to me if the Eclipse plugin completely replaces the need to
I have to edit my question just to make it clear. What I need
Is it possible to not clear entire screen when using glClear() function? I need
I have never posted before so I am sorry if I am not clear.
I apologize in advance if my question is not clear, because I don't know
I'm not clear on how to write simple byte code arrays with ruby, more-so
I am not clear with AP(Wireless Access Point) development, I want to know are
I have read through the facebook developers documentation and it is not clear to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.