Jump to content

SQL statement - urgent help please


applebiz89

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.