Current location: Hot Scripts Forums » Programming Languages » PHP » Avatars near usernames (in forum script)


Avatars near usernames (in forum script)

Reply
  #1 (permalink)  
Old 11-07-11, 01:01 PM
Zets0 Zets0 is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
Avatars near usernames (in forum script)

I made a forum from tutorial. Its was just creating categorys, post, topics. I add profiles, admin panel, few styles. I added avatars in profiles but I cant add them near nicks in posts.
Images are send to database as link that shows path to images in avatars folder on ftp. Links are in 'users' table in row 'user_image'.
Heres part of the code that displays avatar. View.php
PHP Code:

<?php

include 'connect.php';
include 
'header.php';

$username $_SESSION['user_name'];

$query mysql_query(" SELECT * FROM users WHERE user_name='$username'");
if (
mysql_num_rows($query)==0)
    
    die(
"User not found!");

else
    {
        
$row mysql_fetch_assoc($query);
        
$location $row['user_image'];
?>
<div id="avatar">
<?php        
        
echo "<profilemenu><img src='$location' width='150' height='150'></profilemenu>";
        
    }

?>
And heres file that dispaly posts. topic.php:

PHP Code:

<?php

//topic.php
include 'connect.php';
include 
'header.php';
include 
'modules/bbcode.php';

$sql "SELECT
            topic_id,
            topic_subject
        FROM
            topics
        WHERE
            topics.topic_id = " 
mysql_real_escape_string($_GET['id']);
            
$result mysql_query($sql);

if(!
$result)
{
    echo 
'The topic could not be displayed, please try again later.';
}
else
{
    if(
mysql_num_rows($result) == 0)
    {
        echo 
'This topic doesn&prime;t exist.';
    }
    else
    {
        while(
$row mysql_fetch_assoc($result))
        {
            
//display post data
            
echo '<table class="topic" border="1">
                    <tr>
                        <th colspan="2">' 
$row['topic_subject'] . '</th>
                    </tr>'
;
        
            
//fetch the posts from the database
            
$posts_sql "SELECT
                        posts.post_topic,
                        posts.post_content,
                        posts.post_date,
                        posts.post_by,
                        users.user_id,
                        users.user_name
                    FROM
                        posts
                    LEFT JOIN
                        users
                    ON
                        posts.post_by = users.user_id
                    WHERE
                        posts.post_topic = " 
mysql_real_escape_string($_GET['id']);
                        
            
$posts_result mysql_query($posts_sql);
            
            if(!
$posts_result)
            {
                echo 
'<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
            }
            else
            {

                while(
$posts_row mysql_fetch_assoc($posts_result))
                {
                    echo 
'<tr class="topic-post">
                    <img src=""/>
                            <td class="user-post">' 
$posts_row['user_name'] . '<br/>' date('d-m-Y H:i'strtotime($posts_row['post_date'])) . '</td>
                            <td class="post-content">' 
htmlspecialchars(stripslashes($posts_row['post_content'])) . '</td>
                          </tr>'
;
                }
            }
            
            if(!
$_SESSION['signed_in'])
            {
                echo 
'<tr><td colspan=2>You must be <a href="signin.php">signed in</a> to reply. You can also <a href="signup.php">sign up</a> for an account.';
            }
            else
            {
                
//show reply box
                
echo '<tr><td colspan="2"><h2>Reply:</h2><br />
                    <form method="post" action="reply.php?id=' 
$row['topic_id'] . '">
                        <textarea id="elm1" name="reply-content"></textarea><br /><br />
                        <input type="submit" value="Submit reply" />
                    </form></td></tr>'
;
            }
            
            
//finish the table
            
echo '</table>';
        }
    }
}

include 
'footer.php';
?>
Code below is responsible for showing posts. The <img src=""/> shuld be something like ($_SESSION['user_name']) I think.

PHP Code:

        while($posts_row mysql_fetch_assoc($posts_result))

                {
                    echo 
'<tr class="topic-post">
                    <img src=""/>
                            <td class="user-post">' 
$posts_row['user_name'] . '<br/>' date('d-m-Y H:i'strtotime($posts_row['post_date'])) . '</td>
                            <td class="post-content">' 
htmlspecialchars(stripslashes($posts_row['post_content'])) . '</td>
                          </tr>'
;
                } 
Reply With Quote
  #2 (permalink)  
Old 11-15-11, 07:03 AM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
well you could make a function that returns the avatar file name using your code from View.php:

<?

function get_avatar_filename() {
$username = $_SESSION['user_name'];
$query = mysql_query(" SELECT * FROM users WHERE user_name='$username'");
if (mysql_num_rows($query)==0) {
die("User not found!");
}
else {
$row = mysql_fetch_assoc($query);
$location = $row['user_image'];
return $location;
}
}

...and then call that function where you need to display the image:

<td class="user_image"><img src="<? echo get_avatar_filename(); ?>" /></td>

the code is untested but it should work if your View.php works.
__________________
blog.phplabs.net
Reply With Quote
The Following User Says Thank You to phplabs For This Useful Post:
Zets0 (11-17-11)
  #3 (permalink)  
Old 11-15-11, 10:47 AM
Zets0 Zets0 is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
Ok so I change it as You say and view.php now show me this:
Parse error: syntax error, unexpected '}' in /home/a1435968/public_html/view.php on line 26
Looks like on line 26 is } but where to put { .Here View.php:
PHP Code:

<?php

//create_cat.php
include 'connect.php';
include 
'header.php';




function 
get_avatar_filename() {
$username $_SESSION['user_name'];
$query mysql_query(" SELECT * FROM users WHERE user_name='$username'");
if (
mysql_num_rows($query)==0) {
die(
"User not found!");
}
else {
$row mysql_fetch_assoc($query);
$location $row['user_image'];
return 
$location;
}
}
?>
<div id="avatar">
<?php        
        
echo "<profilemenu><img src='$location' width='150' height='150'></profilemenu>";
        
    }

?>
</div>
<div id="nick">
<?php
        
if($_SESSION['signed_in'])
        {
            echo 
'<b>' htmlentities($_SESSION['user_name']) . '</b>';
        }
        
        
?>
</div>
<div id="profile">
<div id="usermenu">
        <a class="item" href="/index.php">Home</a></p>
        <p><a class="item"  href="/upload.php">Upload avatar</a>
        <br/>
        <br/>
        <a class="item" href="/private.php">Messages</a></p>
        
        <a class="item" href="/settings.php">Edit profile</a></p>
        
</div>
</div>

<?php
include 'footer.php';

?>
Reply With Quote
  #4 (permalink)  
Old 11-16-11, 12:46 AM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
sorry, what i mean is that you should add that function into topic.php, not in view.php, and then call it later when you need to get the location of the image.

your view.php was okay, i think. i was showing avatars already, wasn't it?
__________________
blog.phplabs.net
Reply With Quote
The Following User Says Thank You to phplabs For This Useful Post:
Zets0 (11-17-11)
  #5 (permalink)  
Old 11-16-11, 06:01 PM
Zets0 Zets0 is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
Ok so it workd but it show only logged user image. I mean if I login as user Tester then tester image is showing in every avatar. Heres code topic.php:
PHP Code:

<?php

//create_cat.php
include 'connect.php';
include 
'header.php';
include 
'modules/bbcode.php';
require( 
'view2.php');
$sql "SELECT
            topic_id,
            topic_subject
        FROM
            topics
        WHERE
            topics.topic_id = " 
mysql_real_escape_string($_GET['id']);
            
$result mysql_query($sql);

if(!
$result)
{
    echo 
'The topic could not be displayed, please try again later.';
}
else
{
    if(
mysql_num_rows($result) == 0)
    {
        echo 
'This topic doesn&prime;t exist.';
    }
    else
    {
        while(
$row mysql_fetch_assoc($result))
        {
            
//display post data
            
echo '<table class="topic" border="1">
                    <tr>
                        <th colspan="2">' 
$row['topic_subject'] . '</th>
                    </tr>'
;
        
            
//fetch the posts from the database
            
$posts_sql "SELECT
                        posts.post_topic,
                        posts.post_content,
                        posts.post_date,
                        posts.post_by,
                        users.user_id,
                        users.user_name
                    FROM
                        posts
                    LEFT JOIN
                        users
                    ON
                        posts.post_by = users.user_id
                    WHERE
                        posts.post_topic = " 
mysql_real_escape_string($_GET['id']);
                        
            
$posts_result mysql_query($posts_sql);
            
            if(!
$posts_result)
            {
                echo 
'<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
            }
            else
            {

                while(
$posts_row mysql_fetch_assoc($posts_result))
                {
                    echo 
'<tr class="topic-post">
                    
                            <td class="user-post"><img src="' 
.get_avatar_filename().'" />' $posts_row['user_name'] . '<br/>' date('d-m-Y H:i'strtotime($posts_row['post_date'])) . '</td>
                            <td class="post-content">' 
$posts_row['post_content'] . '</td>
                          </tr>'
;
                }
            }
            
            if(!
$_SESSION['signed_in'])
            {
                echo 
'<tr><td colspan=2>You must be <a href="signin.php">signed in</a> to reply. You can also <a href="signup.php">sign up</a> for an account.';
            }
            else
            {
                
//show reply box
                
echo '<tr><td colspan="2"><h2>Reply:</h2><br />
                    <form method="post" action="reply.php?id=' 
$row['topic_id'] . '">
                        <textarea id="elm1" name="reply-content"></textarea><br /><br />
                        <input type="submit" value="Submit reply" />
                    </form></td></tr>'
;
            }
            
            
//finish the table
            
echo '</table>';
        }
    }
}

include 
'footer.php';
?>
Reply With Quote
  #6 (permalink)  
Old 11-17-11, 05:46 AM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
for some reason i thought you wanted to display the avatar for the logged in user well anyway you almost have everything already - just add another field in your select query:

$posts_sql = "SELECT
posts.post_topic,
posts.post_content,
...
users.user_name,
users.user_image
from
...

and then in the table:

<td class="user-post"><img src="' . $posts_row['user_image'] .'" />' . $posts_row['user_name'] . '<br/>' . date('d-m-Y H:i', strtotime($posts_row['post_date'])) . '</td>

i hope it will finally work as you want this time
__________________
blog.phplabs.net
Reply With Quote
The Following User Says Thank You to phplabs For This Useful Post:
Zets0 (11-17-11)
  #7 (permalink)  
Old 11-17-11, 08:44 AM
Zets0 Zets0 is offline
New Member
 
Join Date: Nov 2011
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts
Muahahahaha. You are genious. It works.
So this get_avatar_filename() function is not needed now?

Anyway thx
Reply With Quote
  #8 (permalink)  
Old 11-17-11, 02:21 PM
phplabs phplabs is offline
Newbie Coder
 
Join Date: Oct 2011
Posts: 37
Thanks: 0
Thanked 7 Times in 7 Posts
Quote:
Originally Posted by Zets0 View Post
Muahahahaha. You are genious. It works.
So this get_avatar_filename() functionis not needed now?

Anyway thx
glad it works
yeah, apparently that function is not needed anymore, at least for this task.
__________________
blog.phplabs.net
Reply With Quote
The Following User Says Thank You to phplabs For This Useful Post:
Zets0 (11-17-11)
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Forum Point Script itzball Script Requests 1 07-06-09 03:31 AM
use html to open application absvinyl HTML/XHTML/XML 5 09-18-06 02:04 PM
which forum script? jonathen General HotScripts Site Discussion 15 03-13-05 11:48 PM
php forum script Guyzer General HotScripts Site Discussion 1 01-10-05 11:20 PM


All times are GMT -5. The time now is 08:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.