Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Query from 3 tables
    text
    copied!<p>Using PHP and mySQL. I have 4 total tables, AgencyInfo, TypeCodes, PrimarySta and MutualAid. AgencyInfo has unique ID as the primary. Typecodes has unique TID as the primary. PrimarySta and MutualAid have both ID and TID together as their primary key. </p> <p>I'm trying to create a recordset that will give me records from PrimarySta and MutualAid based on a ID from agencyinfo. There are 47 static records in TypeCodes. PrimarySta and MutualAid will have 47 entries(typecodes) per ID. PrimarySta has ID, TID and 12 INT fields, MutualAid has the same ID, TID and 12 INT fields plus a 13th field(text) called notes.</p> <p>I'm using a while loop to step through the data. ID is passed via POST or SESSION.</p> <pre><code>Page Layout Primary Station TypeCode P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 Mutual Aid M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12 Notes(M13) </code></pre> <p>This is repeated 47 times, once for each typecode. I used Dreamweaver to assemble my initial SQL Query, but from my research, it appears it may not be using the best syntax. I had the following code working with only 2 tables, TypeCodes and PrimarySta, but when I added in MutualAid, something broke. </p> <pre><code>$colname_Display = $_SESSION['sta_id']; } mysql_select_db($database_DB, $MyDB); $query_Display = sprintf("SELECT * FROM primarysta, typecodes, mutualaid WHERE primarysta.tid, mutualaid.tid = typecodes.tid AND primarysta.id = %s", GetSQLValueString($colname_Display, "int")); </code></pre> <p>I'm guessing my problem is with the <code>primarysta.tid, mutualaid.tid = typecodes.tid</code> line. I've seen INNER JOIN used, but can't seem to get the syntax right. </p> <p>Can anyone help me with proper syntax?</p> <p>Thanks!</p>
 

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