applebiz89 Posted May 12, 2009 Share Posted May 12, 2009 Hi, I have these tables $sql_table1 = "CREATE TABLE header ( headerId int NOT NULL AUTO_INCREMENT, fileName varchar(255) NOT NULL, PRIMARY KEY (headerId) )"; if(mysql_query($sql_table1, $dbh)) { print "table 1 created <p>"; } $sql_table2 = "CREATE TABLE vals ( headerFk int NOT NULL, word varchar(255) NOT NULL, PRIMARY KEY (headerFk, word) )"; if(mysql_query($sql_table2,$dbh)) { print "table 2 created <p>"; } And for my search file I want to create an SQL statement that takes a word, searches the database and brings back the filename that, that word is held in. I did have just one table before but i decided to change the style and use two tables with a foreign and primrary key This is the statement I have but doesnt work. $query = "SELECT headerFk FROM vals WHERE word LIKE '%" .$var."%' order by headerId"; $result = mysql_query($query); I can't think of how to bring back the filename from the other table by searching the vals table.. Help greatly appreciated Apple, Link to comment https://forums.phpfreaks.com/topic/157840-sql-statement-urgent-help-please/ Share on other sites More sharing options...
mikr Posted May 12, 2009 Share Posted May 12, 2009 I believe you need to join the tables <?php $query = "SELECT header.fileName FROM header JOIN vals ON header.headerId = vals.headerFk WHERE vals.word LIKE '%" .$var."%' order by header.headerId"; ?> Link to comment https://forums.phpfreaks.com/topic/157840-sql-statement-urgent-help-please/#findComment-832607 Share on other sites More sharing options...
fenway Posted May 13, 2009 Share Posted May 13, 2009 Also, take a look at the rules/TOS -- marking threads as "urgent" isn't going to help. Link to comment https://forums.phpfreaks.com/topic/157840-sql-statement-urgent-help-please/#findComment-833227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.