用where变量组合两个SQL表


Combine two SQL Tables with a where Variable

好像做不对。我试图在我的表单中加入两个表,WHERE是从URL (www.websiste.com?reference=38)获取的变量

两个表有相同的commonkey (ProgramCode)

表1:程序:id_program | ProgramName | ReleaseDate | ProgramCode

表2:id_program_genre | ProgramCode | id_genre

我得到这个,但它不工作

$sql_select = "SELECT * FROM program
                        INNER JOIN ProgramGenre
                            ON program.ProgramCode = ProgramGenre.ProgramCode               
                    WHERE ProgramCode='$_GET[reference]'";

我做错了什么?

尝试使用

$sql_select="SELECT * from programs p,ProgramGenre g where p.ProgramCode=g.ProgramCode and p.ProgramCode='".$_REQUEST['reference']."'";

或者

$sql_select = "SELECT * FROM programs
                        INNER JOIN ProgramGenre
                            ON programs.ProgramCode = ProgramGenre.ProgramCode               
                    WHERE ProgramCode='".$_GET['reference']."'";

SQL不知道ProgramCode指的是哪一列

假设有一个参数化的查询,

$sql_select = "SELECT * FROM program
                    INNER JOIN ProgramGenre
                        ON program.ProgramCode = ProgramGenre.ProgramCode               
                WHERE program.ProgramCode=?";