PHP News Help

Wolverine

Member
Aug 1, 2014
90
3
So I've been working with a RevCMS theme and implanting some features into it (just on my spare time).

I'm trying to get the news author to appear. I only want the author's avatar to appear, I can get an avatar to appear by using {figure} instead, but then it shows the users avatar (not the authors, it shows your avatar if you view the article).

You must be registered for see images attach

Here's my PHP code. I'm most likely fucking it up, but if someone could fix this up, that'd be excellent.
PHP:
                                        <?php
                                        $onlineRow = "SELECT id,username,motto,online,look FROM users";
                                        {
                                        echo'
                                        <div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $onlineRow['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                        <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $onlineRow['username'] .'" style="text-decoration:none;color:#666;">{username}</a><span class="newstext"><b>{newsDate}</b></span></div>
                                        ';}
                                       ?>
 

Kodys

lmao
Oct 24, 2016
36
17
There's two solutions, the first one is if you're using $_GET['id'] in the news.php file and the second is if you're not. (Most likely use the second method)
As I have no idea at all what you've named the variable you're using if you'll have to change $changeme in the code I've wrote to the variable.
PHP:
    $author= mysql_query("SELECT * FROM users WHERE username = ".$changeme['author']);
    echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='.$author['look'].'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
          <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'.$author['username'].'" style="text-decoration:none;color:#666;">'.$author['username'].'</a><span class="newstext"><b>{newsDate}</b></span></div>
In class.forms.php located in app/tpl/ you can replace the getPageNews function with the following below.
PHP:
final public function getPageNews()
    {
        global $template, $engine;
  
            if(!isset($_GET['id']) || !is_numeric($_GET['id']))
            {
                $_GET['id'] = 1;
            }
                $result = mysql_query("SELECT title, id FROM cms_news WHERE id != '" . $engine->secure($_GET['id']) . "' ORDER BY id DESC");
          
                while($news1 = mysql_fetch_array($result))
                {
                    $template->setParams('newsList', '&laquo; <a href="index.php?url=news&id='.$news1["id"].'">' . $news1['title'] . '</a><br/>');
                }
          
                $news = $engine->fetch_assoc("SELECT title, longstory, author, published FROM cms_news WHERE id = '" . $engine->secure($_GET['id']) . "' LIMIT 1");
                $author = $engine->fetch_assoc("SELECT look FROM users WHERE username = ".$news['author']." LIMIT 1");
                $template->setParams('newsTitle', $news['title']);
                $template->setParams('newsContent', $news['longstory']);
                $template->setParams('newsAuthor', $news['author']);
                $template->setParams('newsDate', date("d-m-y", $news['published']));
                $template->setParams('authorLook', $author['look']);
      
                unset($result);
                unset($news1);
                unset($news);
    }
This would allow you to use {authorLook} to show their look in your current code. Instead of using $onlineRow['look'].
Just something to point out is that when you're creating a link to their home page you're using {username} when you should be using {newsAuthor}.
 
Last edited:

Wolverine

Member
Aug 1, 2014
90
3
There's two solutions, the first one is if you're using $_GET['id'] in the news.php file and the second is if you're not. (Most likely use the second method)
As I have no idea at all what you've named the variable you're using if you'll have to change $changeme in the code I've wrote to the variable.
PHP:
    $author= mysql_query("SELECT * FROM users WHERE username = ".$changeme['author']);
    echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='.$author['look'].'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
          <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'.$author['username'].'" style="text-decoration:none;color:#666;">'.$author['username'].'</a><span class="newstext"><b>{newsDate}</b></span></div>
In class.forms.php located in app/tpl/ you can replace the getPageNews function with the following below.
PHP:
final public function getPageNews()
    {
        global $template, $engine;
 
            if(!isset($_GET['id']) || !is_numeric($_GET['id']))
            {
                $_GET['id'] = 1;
            }
                $result = mysql_query("SELECT title, id FROM cms_news WHERE id != '" . $engine->secure($_GET['id']) . "' ORDER BY id DESC");
         
                while($news1 = mysql_fetch_array($result))
                {
                    $template->setParams('newsList', '&laquo; <a href="index.php?url=news&id='.$news1["id"].'">' . $news1['title'] . '</a><br/>');
                }
         
                $news = $engine->fetch_assoc("SELECT title, longstory, author, published FROM cms_news WHERE id = '" . $engine->secure($_GET['id']) . "' LIMIT 1");
                $author = $engine->fetch_assoc("SELECT look FROM users WHERE username = ".$news['author']." LIMIT 1");
                $template->setParams('newsTitle', $news['title']);
                $template->setParams('newsContent', $news['longstory']);
                $template->setParams('newsAuthor', $news['author']);
                $template->setParams('newsDate', date("d-m-y", $news['published']));
                $template->setParams('authorLook', $author['look']);
     
                unset($result);
                unset($news1);
                unset($news);
    }
This would allow you to use {authorLook} to show their look in your current code. Instead of using $onlineRow['look'].
Just something to point out is that when you're creating a link to their home page you're using {username} when you should be using {newsAuthor}.
I tried the second option, but that doesn't seem to wanna read their avatar.
You must be registered for see images attach

PHP:
                                        <?php
                                        $onlineRow = mysql_query("SELECT id,username,motto,online,look FROM users WHERE id = '" . $_SESSION['user']['id'] . "'");
                                        while($online = mysql_fetch_assoc($onlineRow))
                                        {
                                        echo'
                                        <div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure={authorLook}&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                        <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/{newsAuthor}" style="text-decoration:none;color:#666;">{username}</a><span class="newstext"><b>{newsDate}</b></span></div>
                                        ';}
                                       ?>
 

Kodys

lmao
Oct 24, 2016
36
17
I tried the second option, but that doesn't seem to wanna read their avatar.
You must be registered for see images attach

PHP:
$onlineRow = mysql_query("SELECT id,username,motto,online,look FROM users WHERE id = '" . $_SESSION['user']['id'] . "'");
                                        while($online = mysql_fetch_assoc($onlineRow))
                                        {
                                        echo'
                                        <div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure={authorLook}&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                        <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/{newsAuthor}" style="text-decoration:none;color:#666;">{username}</a><span class="newstext"><b>{newsDate}</b></span></div>
                                        ';}
I figured that option wouldn't work entirely but first the whole $onineRow doesn't do anything at all and I have no idea at all in why it's there how I think the below might work.
PHP:
<?php
    $news= mysql_query("SELECT look FROM users WHERE username = {newsAuthor}'");
    while($n= mysql_fetch_assoc($news))
        {
            echo'<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure=".$n['look']."&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
            <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/".$n['username']." style="text-decoration:none;color:#666;">".$n['username']."</a><span class="newstext"><b>{newsDate}</b></span></div>';
        }
?>
If that doesn't work I'll explain using the _GET method in more detail and how to use it.
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,199
3,934
This should do it.

However, you need to get the author username or ID (please use ID, much better). So either another query for pulling that ID from the articles table, or move this into class.forms.php as suggested above.

PHP:
<?php

$getAuthor = mysql_query("SELECT `id`,`username`,`motto`,`online`,`look` FROM `users` WHERE `something` = '' LIMIT 1");

if (mysql_num_rows($getAuthor) > 0)
{
    $author = mysql_fetch_assoc($getAuthor);

    echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $author['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
    <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $author['username'] .'" style="text-decoration:none;color:#666;">'. $author['username'] .'</a><span class="newstext"><b>{newsDate}</b></span></div>';
}
?>
 

Wolverine

Member
Aug 1, 2014
90
3
I figured that option wouldn't work entirely but first the whole $onineRow doesn't do anything at all and I have no idea at all in why it's there how I think the below might work.
PHP:
<?php
    $news= mysql_query("SELECT look FROM users WHERE username = {newsAuthor}'");
    while($n= mysql_fetch_assoc($news))
        {
            echo'<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure=".$n['look']."&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
            <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/".$n['username']." style="text-decoration:none;color:#666;">".$n['username']."</a><span class="newstext"><b>{newsDate}</b></span></div>';
        }
?>
If that doesn't work I'll explain using the _GET method in more detail and how to use it.
Page wont load after inserting that.

This should do it.

However, you need to get the author username or ID (please use ID, much better). So either another query for pulling that ID from the articles table, or move this into class.forms.php as suggested above.

PHP:
<?php

$getAuthor = mysql_query("SELECT `id`,`username`,`motto`,`online`,`look` FROM `users` WHERE `something` = '' LIMIT 1");

if (mysql_num_rows($getAuthor) > 0)
{
    $author = mysql_fetch_assoc($getAuthor);

    echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $author['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
    <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $author['username'] .'" style="text-decoration:none;color:#666;">'. $author['username'] .'</a><span class="newstext"><b>{newsDate}</b></span></div>';
}
?>
So, how would I proceed with this? Where 'something' is, and also the '', what could I substitute into there?

Edit: So I've been playing with your query, but I cannot seem to get it down. Here's what I have so far:
PHP:
                                        <?php

                                        $getAuthor = mysql_query("SELECT `id`,`username`,`motto`,`online`,`look` FROM `users` WHERE username = ". $author['username'] ." LIMIT 1");

                                        if (mysql_num_rows($getAuthor) > 0)
                                        {
                                            $author = mysql_fetch_assoc($getAuthor);

                                            echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $author['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                            <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $author['username'] .'" style="text-decoration:none;color:#666;">'. $author['username'] .'</a><span class="newstext"><b>{newsDate}</b></span></div>';
                                        }
                                        ?>
Although it is probably wrong, it doesn't display as it should anymore, the user avatar and userbox has vanished.
You must be registered for see images attach
 
Last edited:

Blasteh

big tits
Apr 3, 2013
1,156
521
Page wont load after inserting that.


So, how would I proceed with this? Where 'something' is, and also the '', what could I substitute into there?

Edit: So I've been playing with your query, but I cannot seem to get it down. Here's what I have so far:
PHP:
                                        <?php

                                        $getAuthor = mysql_query("SELECT `id`,`username`,`motto`,`online`,`look` FROM `users` WHERE username = ". $author['username'] ." LIMIT 1");

                                        if (mysql_num_rows($getAuthor) > 0)
                                        {
                                            $author = mysql_fetch_assoc($getAuthor);

                                            echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $author['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                            <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $author['username'] .'" style="text-decoration:none;color:#666;">'. $author['username'] .'</a><span class="newstext"><b>{newsDate}</b></span></div>';
                                        }
                                        ?>
Although it is probably wrong, it doesn't display as it should anymore, the user avatar and userbox has vanished.
You must be registered for see images attach
If it doesn't display, then you're messing up somewhere. I think you need to use the $_GET method as @Kodys stated. I'm unsure on how that works, he will probably know though.
 

Kodys

lmao
Oct 24, 2016
36
17
Page wont load after inserting that.


So, how would I proceed with this? Where 'something' is, and also the '', what could I substitute into there?

Edit: So I've been playing with your query, but I cannot seem to get it down. Here's what I have so far:
PHP:
                                        <?php

                                        $getAuthor = mysql_query("SELECT `id`,`username`,`motto`,`online`,`look` FROM `users` WHERE username = ". $author['username'] ." LIMIT 1");

                                        if (mysql_num_rows($getAuthor) > 0)
                                        {
                                            $author = mysql_fetch_assoc($getAuthor);

                                            echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $author['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                            <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $author['username'] .'" style="text-decoration:none;color:#666;">'. $author['username'] .'</a><span class="newstext"><b>{newsDate}</b></span></div>';
                                        }
                                        ?>
Although it is probably wrong, it doesn't display as it should anymore, the user avatar and userbox has vanished.
You must be registered for see images attach
As you can see in your code $author['username'] isn't used anywhere in there so it's not going to return anything at all.
Now this is assuming that your news article urls are something like hotel.url/index.php?url=news&id=# and the # being the article id number. Read along the comments I've put in place if you want a better understanding of what's being done.
PHP:
<?php
    if(!isset($_GET['id']) || !is_numeric($_GET['id'])) //if the news id is null OR isn't a number
    {
        $_GET['id'] = 1; //set the news id to 1 (this is what's done in class.forms.php meaning it'll match the article shown)
    }
 
    //take the information containing the author username from the cms_news table and store it into $author
    $author = mysql_query("SELECT author FROM cms_news WHERE id = ".$_GET['id']);
 
    //select everything from the users table where the username is the same as who posted it
    $a = mysql_query("SELECT * FROM users WHERE username = ".$author['author'];
    $look= $a['look']; //using $look rather than $a['look'] so it's less complicated
    $user = $a['username']; //storing the username here too because why not
 
    echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='.$look.'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
          <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'.$user.'" style="text-decoration:none;color:#666;">'.$user.'</a><span class="newstext"><b>{newsDate}</b></span></div>';
?>
If your news article url isn't index.php?url=news&id=# write down below what the url of your news looks like, if it's just hotel.url/news create a second article and show me the url of that one.

Edit: So I've been playing with your query, but I cannot seem to get it down. Here's what I have so far:
PHP:
                                        <?php

                                        $getAuthor = mysql_query("SELECT `id`,`username`,`motto`,`online`,`look` FROM `users` WHERE username = ". $author['username'] ." LIMIT 1");

                                        if (mysql_num_rows($getAuthor) > 0)
                                        {
                                            $author = mysql_fetch_assoc($getAuthor);

                                            echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='. $author['look'] .'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                            <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'. $author['username'] .'" style="text-decoration:none;color:#666;">'. $author['username'] .'</a><span class="newstext"><b>{newsDate}</b></span></div>';
                                        }
                                        ?>
Although it is probably wrong, it doesn't display as it should anymore, the user avatar and userbox has vanished.
You must be registered for see images attach
The reason why the avatar, userbox etc has disappeared is because it'll only show if the query $getAuthor comes back any data, which it doesn't (I stated before $author did nothing) so it'll skip the code to echo them boxes.

As @Sledmore mentioned it's much better to store the Author ID rather than username incase of username changes, if you'd like me to explain how that would be done say so along with posting the news article writer in your housekeeping file here.
 
Last edited:

Wolverine

Member
Aug 1, 2014
90
3
As you can see in your code $author['username'] isn't used anywhere in there so it's not going to return anything at all.
Now this is assuming that your news article urls are something like hotel.url/index.php?url=news&id=# and the # being the article id number. Read along the comments I've put in place if you want a better understanding of what's being done.
PHP:
<?php
    if(!isset($_GET['id']) || !is_numeric($_GET['id'])) //if the news id is null OR isn't a number
    {
        $_GET['id'] = 1; //set the news id to 1 (this is what's done in class.forms.php meaning it'll match the article shown)
    }
 
    //take the information containing the author username from the cms_news table and store it into $author
    $author = mysql_query("SELECT author FROM cms_news WHERE id = ".$_GET['id']);
 
    //select everything from the users table where the username is the same as who posted it
    $a = mysql_query("SELECT * FROM users WHERE username = ".$author['author'];
    $look= $a['look']; //using $look rather than $a['look'] so it's less complicated
    $user = $a['username']; //storing the username here too because why not
 
    echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='.$look.'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
          <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'.$user.'" style="text-decoration:none;color:#666;">'.$user.'</a><span class="newstext"><b>{newsDate}</b></span></div>';
?>
If your news article url isn't index.php?url=news&id=# write down below what the url of your news looks like, if it's just hotel.url/news create a second article and show me the url of that one.


The reason why the avatar, userbox etc has disappeared is because it'll only show if the query $getAuthor comes back any data, which it doesn't (I stated before $author did nothing) so it'll skip the code to echo them boxes.

As @Sledmore mentioned it's much better to store the Author ID rather than username incase of username changes, if you'd like me to explain how that would be done say so along with posting the news article writer in your housekeeping file here.
Yeah, I'm lost as fuck. I cannot get it.

Addnews.php:
News.php (in skins folder/{skin}):
 

Kodys

lmao
Oct 24, 2016
36
17
If you're going to be using the Author ID rather than username use both of these: , . One thing to note is while using the news.php you will have to create new articles so it uses the id.
 

Wolverine

Member
Aug 1, 2014
90
3
If you're going to be using the Author ID rather than username use both of these: , . One thing to note is while using the news.php you will have to create new articles so it uses the id.
When I do that, it comes back with this error.
You must be registered for see images attach
 

Kodys

lmao
Oct 24, 2016
36
17
Apologises for late reply I fell asleep, make sure it's not an username in the cms_news table under author, change it to your id and use the addnews.php so it'll always place in their ID.
 

Blasteh

big tits
Apr 3, 2013
1,156
521
Apologises for late reply I fell asleep, make sure it's not an username in the cms_news table under author, change it to your id and use the addnews.php so it'll always place in their ID.
But, if he tries to get the ID it won't display the username of the author. It's not too appealing to see '238' as your news author.
 

Kodys

lmao
Oct 24, 2016
36
17
But, if he tries to get the ID it won't display the username of the author. It's not too appealing to see '238' as your news author.
Yeah, I've made sure it would say the username of the ID by using
PHP:
                                           $author = mysql_query("SELECT author FROM cms_news WHERE id = ".$_GET['id']);
                                           $a = mysql_query("SELECT * FROM users WHERE id = ".$author['author']);
This gets the ID of who posted the news article then grabs the username from the users table and it'll display that rather than 238.
 

Wolverine

Member
Aug 1, 2014
90
3
Yeah, I've made sure it would say the username of the ID by using
PHP:
                                           $author = mysql_query("SELECT author FROM cms_news WHERE id = ".$_GET['id']);
                                           $a = mysql_query("SELECT * FROM users WHERE id = ".$author['author']);
This gets the ID of who posted the news article then grabs the username from the users table and it'll display that rather than 238.
It doesn't display anything, in CMS_news it is displaying the number so id = '1' in my case. Under the author tab, it says '1'.
You must be registered for see images attach
 

Kodys

lmao
Oct 24, 2016
36
17
In your news replace the php section with this.
PHP:
                                       <?php
                                            if(!isset($_GET['id']) || !is_numeric($_GET['id']))
                                            {
                                                $_GET['id'] = 1;
                                            }
                                            $author = mysql_fetch_array(mysql_query("SELECT author FROM cms_news WHERE id = ".$_GET['id']));
                                            $a = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id = ".$author['author']));
                                            $look = $a['look'];
                                            $user = $a['username'];
                                            echo '<div id="userAvatar" style="margin-bottom: 10px;;float:left;width: 75px;height:70px;background: url(http://avatar-retro.com/habbo-imaging/avatarimage?figure='.$look.'&amp;action=drk&amp;direction=3&amp;head_direction=3&amp;gesture=sml&amp;size=1) no-repeat;"></div>
                                                  <div id="slickTitle" style="margin-top:17px;" class="newsAuthor"><a href="/home/'.$user.'" style="text-decoration:none;color:#666;">'.$user.'</a><span class="newstext"><b>{newsDate}</b></span></div>';
                                        ?>
 

Users who are viewing this thread

Top