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