Jump to content

Recommended Posts

I need some help.. I have two separate database tables.  What I need to do is display the data from one if a variable exists in another.  Heres my statement that pulls the correct data from one.  But how do I attach the other so it's only pulling the data from the tables if the ID number is a certain one. 

 

	$strQuery				= "SELECT intID, strTypeName FROM tblTypes WHERE boolActive = 1 ORDER BY intSortOrder ASC, strTypeName ASC";
	$queryGetTypes			= db_query($strQuery);

 

The table I need to join has the following fields: intID, intTypeID, intCategoryID

I need to pull the data for the intCategoryID=1 for example. 

 

Please help!

 

Link to comment
https://forums.phpfreaks.com/topic/209667-join-statement/
Share on other sites

Thanks... So I think i'm pretty close, i'v seemed to make the join statement, just need a little help on completing this full statement. I got this but it's pulling the first field and repeating it instead of listing all the ones with that ID

 

<?php
// Make a MySQL Connection
// Construct our join query
$query = "SELECT 
    * 
FROM 
     tblTypes
JOIN 
    tblTypeToCategory 
ON 
   strTypeName=intCategoryID WHERE intCategoryID = 1 ORDER BY intSortOrder ASC, strTypeName ASC";

$result = mysql_query($query) or die(mysql_error());


// Print out the contents of each row into a table 
while($row = mysql_fetch_array($result)){
echo $row['strTypeName']. " - ". $row['intCategoryID'];
echo "<br />";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/209667-join-statement/#findComment-1094606
Share on other sites

Well now that i'm looking at this might need to join 3 to get these results.  Here is the structure

 

tblTypes

intID  strTypeName

 

tblTypeToCategory

intID  intTypeID  intCategoryID

 

tblCategories

intID  strCategoryName 

 

Ideally what I need is tblTypes to pull all the names that are associated with tblCategories specific ID

 

So for example. 

tblTypes has Item 1, Item 2, Item 3

 

tblTypeToCategory has the category ID's and Type ID

 

tblCategories has the main ID that we are looking to pull so the TypeToCategory is basically the bridge between the two

Link to comment
https://forums.phpfreaks.com/topic/209667-join-statement/#findComment-1094629
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.