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

  • SEARCH
  • Home
  • 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 6761047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:08:23+00:00 2026-05-26T14:08:23+00:00

I have this code: if ($firearm != ) { $sql_result5 = mysql_query(SELECT icon FROM

  • 0

I have this code:

if ($firearm != "") { 
  $sql_result5 = mysql_query("SELECT icon FROM db_firearms WHERE name='$firearm'", $db); 
  $rs5 = mysql_fetch_array($sql_result5); $firearm_icon=$rs5[icon]; 
  }

if ($item != "") {
  $sql_result5 = mysql_query("SELECT icon FROM db_items WHERE name='$item'", $db); 
  $rs5 = mysql_fetch_array($sql_result5); $item_icon=$rs5[icon]; 
  }

if ($vehicle != "") { 
  $sql_result5 = mysql_query("SELECT icon FROM db_vehicles WHERE name='$vehicle'", $db); 
  $rs5 = mysql_fetch_array($sql_result5); $vehicle_icon=$rs5[icon]; 
  }

if ($melee != "") {
  $sql_result5 = mysql_query("SELECT icon FROM db_melee WHERE name='$melee'", $db);
  $rs5 = mysql_fetch_array($sql_result5); $melee_icon=$rs5[icon];
  }

This code is being refreshed every 10 seconds on a part of my page showing the players equipment. Would it be best to have this in one query, to save db resources?

If so, how would I write that? Would it be INNER JOINS? normal JOINS?

  • 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-05-26T14:08:24+00:00Added an answer on May 26, 2026 at 2:08 pm

    You’d use a union, with a bit of fireproofing in case you get no match on a name:

    Code example to work around broken DB-design

    $sql = "
      (SELECT 'fire' as id, icon FROM db_firearms WHERE name='$firearm' LIMIT 1)
    UNION ALL
      (SELECT 'item' as id, icon FROM db_items WHERE name='$item' LIMIT 1)
    UNION ALL
      (SELECT 'vehi' as id, icon FROM db_vehicles WHERE name='$vehicle' LIMIT 1)
    UNION ALL
      (SELECT 'melee' as id, icon FROM db_melee WHERE name='$melee' LIMIT 1)
    ";
    $result = mysql_query($sql);
    if ($result) {
      while ($row = mysql_fetch_array($result)) {
        if ($row['id'] == 'fire') {$fireicon = $row['icon'];}
        elseif ($row['id'] == 'item') {$itemicon = $row['icon'];}
        elseif ($row['id'] == 'vehi') {$vehiicon = $row['icon'];}
        elseif ($row['id'] == 'melee') {$meleeicon = $row['icon'];}
      }
    }
    

    The union all stops MySQL trying to eliminate duplicates, speeding up the query.

    Better solution

    You should really put all your icons in one table

    TABLE icons
      user_id
      icon_type ENUM('gun','item','melee','vehicle')
      icon blob
      primary key (user_id, icon_type)
    

    Now you can select

    SELECT icon_type, icon FROM icons WHERE user_id = '$user_id';
    

    But of course this really depends of the details of your application.
    My point is just that UNION is a warning sign that you’re doing something wrong or unusual

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to get a row from a JTable that is generated
I have this code which depends on this javascript from dynamic drive: http://dynamicdrive.com/dynamicindex16/formdependency.htm Its
i have this code where you can select the date you like to attend
I have this code: <ComboBox Width=100 ItemsSource={Binding FontList} x:Name=fontComboFast> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate>
I have this code in my View.. <tr><td>Account:</td><td><%=Html.DropDownList(drdAccounts,Model.AccountsListHeader),Model.selectedAccount,Select Account, new { onchange = JavaScript:AccountChanged()
I have this code var contacts = dr.mktDoctorContacts .GroupBy(x => x.ContactType) .Select(zb => new
I have this code from a coworker (probably got it from the web somewhere)
I have this code that is captured in the jquery Data object from a
I have this code: @this.Html.DropDownListFor(vm => vm.FishId, new SelectList(this.Model.Fishies, FishId, FishName, this.Model.FishId), Please Select
I have this code in jQuery, that I want to reimplement with the prototype

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.