简体   繁体   中英

mysql isn't joining data

I get the code to load the pages initially with sports, entertainment and want-ads but when i push the button i get all of the articles instead of the ones that correlate with the page chosen. What i would like to happen is when i push the sports button I get all of the articles related to sports (with no entertainment or want-ad articles). I have a database with tables as follows:

TABLES ARE AS FOLLOWS:

PAGES-
pages.pageId(INT),
pages.pageTitle(VARCHAR),

ARTICLES-
articles.acrticleId(INT),
articles.articleTitle(VARCHAR),
articles.pageId(INT),

VIDEOS-
videos.videoId(INT),
videos.videoTitle(VARCHAR),
videos.videoLoc(VARCHAR),
videos.articlesId(INT),

IMAGES-
images.imageId(INT),
images.imageTitle(VARCHAR),
images.imageLoc(VARCHAR),
images.articlesId(INT),

TEXT-
text.textId(INT),
text.text(medium),
text.articlesId(INT),

I have a query that brings in all the pages with a while loop:

$sqlPAQuery = "SELECT pages.pageId, pages.pageTitle, articles.articleId, 
articles.articleTitle FROM pages, articles GROUP BY pages.pageTitle";
$paqueryResult = mysqli_query($conn,$sqlPAQuery);

while ($paqueryRow = mysqli_fetch_object($paqueryResult))
{

    $pages = "<a href = articles.php?pageId=".$paqueryRow->pageId." data-
    role='button' ><button id ='wrapper'>".$paqueryRow->pageTitle."</button>
    </a><br/><br/>";
    echo $pages;
}

when a button is pushed it brings in this query:

SELECT pages.pageId, pageTitle, articles.articleId, articles.articleTitle, 
GROUP_CONCAT(articleTitle)
FROM articles join pages using (pageId)
GROUP BY pageId

the html/javascript to send the info is:

<div data-role="content" >
   <p>Is Nursing For You?</p>
    <br/>
        <div id = "div1" align="center"></div>
</div>




    </div> 
<script type='text/javascript'>
$(document).ready(function() {
   $("#div1").load('FONWVhp.php', function() {
       $('#div1 a').button();
 });

$(document).on('click', '#div1 a', function(event){
        event.preventDefault();
       //   alert($(this).attr('href'));
        $("#div1").load(($(this).attr('href')), function() {
            $('#div1 a').button();
        });
    });

    $(document).on('click', '#div1 a', function(event){
        event.preventDefault();
        //alert($(this).attr('href'));
        $("#div1").load(($(this).attr('href')), function() {
            $('#div1 a').button();
        });
    });
});

You have to modify your query a little bit, Just you have to do is to add where clause in it. Like this:

SELECT pages.pageId, pageTitle, articles.articleId, articles.articleTitle
FROM articles join pages using (pageId)
where pageId = 'current_page_id'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM