Jump to content

Query Joining Help


Andy11548

Recommended Posts

I've tried joining querys, but I have no bloody clue what I'm doing lol.

 

I'm using 2 querys, one to show the news, and one to pull the username from the id.

 

If anyone could help, it'd be great.

 

<?php include './includes/mysql/connect.php'; ?>
<!DOCTYPE HTML>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="Andy" />
    <link href="./includes/css/css.css" rel="stylesheet" type="text/css" />

<title>Project Desination</title>
</head>
<body>
<div id="wrapper">
    <div id="header">
        <div id="logo"></div>
        <div id="navMenu">
            <ul>
                <li><a href="index.php">Home</a></li>
                <li><a href="./forums/">Forums</a></li>
            </ul>
        </div>
    </div>
    <div id="contentHolder">
        <div id="content">
            <?php
            $query = mysql_query("
            SELECT
            t1.post_id as PostID
            t1.poster_id as User
            t1.forum_id as Forum
            t1.post_subject as Title
            t1.post_text as Content
            (SELECT COUNT(*) FROM `phpbb_posts` as t2 WHERE t2.forum_id = '8') as NewsCount
            
            FROM 
            
            phpbb_posts as t1
                INNER JOIN phpbb_users as t2
                    ON t2.user_id = t1.poster_id
            
            ORDER BY t1.post_id DESC
            ");
            
            if(mysql_num_rows($query) != 0)
            {
                while($newsF = mysql_fetch_assoc($query))
                {
                    echo '<div id="title">'.$newsF['post_subject'].'</div>';
                    echo '<div id="text">'.$newsF['post_text'].'</div>';
                    echo '<div id="author"></div><br /><br />';
                }
            } else {
                echo 'There is no news to be displayed.';
            }
            ?>
        </div>
        <div id="recent">Testing</div>
    </div>
    <div class="clearFloat"></div>
    <div id="push"></div>
</div>
    <div id="footer">
        <span class="middle"></span>
    </div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/256429-query-joining-help/
Share on other sites

Hi

 

Only thing I can spot wrong is that you have given alias' to some of the columns brought back by the SQL but then referred to the column names rather than the alias names when outputting them (eg you have used $newsF['post_subject'] rather than $newsF['Title'])

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/256429-query-joining-help/#findComment-1315099
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.