Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question is clear, but your code example has alot of formatting issues and I cannot give you direct answer, based on your example code.</p> <p>The reason, why your example is unclear, is because.. with what are you going to join the tables? From one table you are selecting by <code>name='$rs[firearm]'</code> and from another by <code>player='$id'</code>. You have to provide the hidden data, like <code>$rs</code> and also <code>$id</code>.</p> <p>You should definitely read these about <a href="http://www.tizag.com/mysqlTutorial/mysqljoins.php" rel="nofollow noreferrer">mysql join</a> and <a href="http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php" rel="nofollow noreferrer">mysql left join</a>. But I will try to give you an example based on your code, with fixed syntax. (Keep in mind, that I'm no mysql join expert, I did not test this code and also I do not know the joining conditions.) And also, the system structure is unclear.</p> <p>As I understood, this what your tables do, correct?</p> <ul> <li><strong>mobsters</strong> - <em>Users</em> table</li> <li><strong>items_firearms</strong> - Links from <em>users</em> table to <em>items</em> table</li> <li><strong>db_firearms</strong> - <em>Items</em> table</li> </ul> <p>So basically, my example does this: It will have preloaded <code>$rs</code> value, from the <em>users</em> table. It will check, if there is a entry inside the <em>links</em> table and hook the result with them <em>items</em> table. However, if the <em>links</em> table or even the <em>items</em> table can return multiple entries, then this doesn't work and you need to loop your results in much more smarter way.</p> <pre><code>// I can only assume, that $id is the ID of the player $id = 2; // Since I dont know the $rs value, then Im going to make some up $rs = array( 'id' =&gt; 33, 'firearm' =&gt; 'famas' ); if ($rs['firearm']) { $result = mysql_fetch_array(mysql_query("SELECT ifa.*, dbfa.* FROM `items_firearms` AS `ifa` LEFT JOIN `db_firearms` AS `dbfa` ON `ifa.shortname` = `dbfa.shortname` WHERE `ifa.player` = '$id'")); if ($result['id']) { mysql_query("UPDATE `mobsters` SET `firearm` = '' WHERE `id` = '$id'", $db); } } </code></pre> <p>It is pretty clear, that you are new to PHP and mysql.. So I think you should probably edit your question and talk about your higher goal. Briefly mention, what your application are you building..? What are you trying to do with the mysql queries..? Maybe provide the table structure of your mysql tables..? I'm sure, that you will get your questions votes back to normal and also we can help you much better.</p> <p><strong>NOTES</strong></p> <ul> <li>You have to quote these types of variables: <code>$rs[firearm]</code> -> <code>$rs['firearm']</code></li> <li>If you want to check if your $rs['firearm'] equals something, then there is a better way then <code>$rs[firearm] != ""</code>. The most simple is <code>if ($rs['firearm']) {echo 'foo';}</code>, but will produce a notice message, when all errors reporting mode. You can use <a href="http://php.net/manual/en/function.isset.php" rel="nofollow noreferrer"><code>isset()</code></a> and <a href="http://php.net/manual/en/function.empty.php" rel="nofollow noreferrer"><code>empty()</code></a>, but keep in mind, that <a href="http://php.net/manual/en/function.isset.php" rel="nofollow noreferrer"><code>isset()</code></a> checks whether the variable has been set.. Meaning, even if its false, then it has been set. <a href="http://php.net/manual/en/function.empty.php" rel="nofollow noreferrer"><code>empty()</code></a> reacts to undefined and empty variable the same, without any messages.</li> <li>Also, <code>""</code> means <code>NULL</code>, so if you even need to use <code>""</code>, then use <code>NULL</code> instead...much neater way..</li> <li>I strongly recommend to use mysql class. You can understand the basics behind that idea from <a href="https://stackoverflow.com/questions/7264203/load-db-password-and-keys-into-phps-memory-on-startup/7264426#7264426">this answer</a>. This is gonna make things much more easier for you. Also, mysql class is a must-have when dealing with dynamic applications.</li> <li><code>if ($rs3[$rs2[shortname]] &lt; 1) { ..</code> makes no sense.. Do you want to check if the value is empty? Then (simple): <code>if (!$rs3[$rs2[shortname]]) { ..</code> and a very strict standard: <code>if (empty($rs3[$rs2[shortname]])) { ..</code></li> <li>Also you have to quote your sql queries, see my examples above.</li> <li>Is the last mysql query missing $db?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload