datoshway Posted November 17, 2011 Share Posted November 17, 2011 The following is querying one table. I need this to query two tables and display the results. $strQuery = "SELECT * FROM tblDocuments ORDER BY dtAdded DESC"; $queryGetNews = db_query($strQuery); Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/ Share on other sites More sharing options...
Adam Posted November 17, 2011 Share Posted November 17, 2011 What kind of JOIN? What other table? Which columns are related? Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1288909 Share on other sites More sharing options...
datoshway Posted November 17, 2011 Author Share Posted November 17, 2011 The related column is strMessage. Basically need to pull strMessage from both tables. Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1288939 Share on other sites More sharing options...
fenway Posted November 18, 2011 Share Posted November 18, 2011 SELECT * FROM tblDocuments INNER JOIN theOtherTable ON ( theOtherTable.strMessage = tblDocuments.strMessage ) ORDER BY tblDocuments.dtAdded DESC" Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1289177 Share on other sites More sharing options...
datoshway Posted November 18, 2011 Author Share Posted November 18, 2011 Thank you! For some reason i'm only getting two results from one table with that query. There should be 3 results if we were getting data from both tables. Below is my full code. Any ideas on where the snag might be? $strQuery = "SELECT * FROM tblDocuments INNER JOIN tblCleaning ON ( tblCleaning.strMessage = tblDocuments.strMessage ) ORDER BY tblDocuments.dtAdded DESC"; $queryGetNews = db_query($strQuery); <?php if (db_num_rows($queryGetNews) > 0) { while ($objRow = db_fetch_object($queryGetNews)) { $intRowID = intval($objRow->intID); $strRowName = stripslashes($objRow->strHeadline); $strMessage = stripslashes($objRow->strMessage); $dtAdded = date("m/d/Y", strtotime($objRow->dtAdded)); ?> <div id="messages" style="border:1px solid #999; width:430px; height:26px; line-height:26px; margin-bottom:3px; padding-left:5px;"><?php echo $dtAdded; ?> - <?php echo $strMessage; ?></div> <?php } db_free_result($queryGetNews); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1289188 Share on other sites More sharing options...
fenway Posted November 18, 2011 Share Posted November 18, 2011 I don't need to see you code, I need to see you data. Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1289383 Share on other sites More sharing options...
datoshway Posted November 18, 2011 Author Share Posted November 18, 2011 huh? Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1289385 Share on other sites More sharing options...
fenway Posted November 18, 2011 Share Posted November 18, 2011 You're telling me the database is wrong. I'm telling you to show me the 3 records from each table that match on strMessage. Quote Link to comment https://forums.phpfreaks.com/topic/251287-help-with-join-query/#findComment-1289412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.