[Help] This Guestbook code

1.05K
.
Azhar-Ali

Wapmasters i am pasting the code in my mainpage.php

Code (+/-)
defined('_IN_JOHNCMS') or die('Error: restricted access');
$r=rand(1000,9999);
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `guest` WHERE `adm`='0'"), 0);
if ($user_id && !$ban['13']) {
    echo '<div class="title">site - ShoutBox</div> <form action="/guestbook/index.php" method="post"> <div style="display:none"><textarea rows="3" cols="20" name="text" style="width:auto"></textarea></div> 
 <input type="submit" value="Add Shout Message"/></form><br/>';
    if  ($total) {
        $req = mysql_query("SELECT `guest`.*, `guest`.`id` AS `gid`, `users`.`rights`, `users`.`lastdate`, `users`.`sex`,  `users`.`datereg`, `users`.`id`
FROM `guest` LEFT JOIN `users` ON `guest`.`user_id` = `users`.`id`
WHERE `guest`.`adm`='0' ORDER BY `time` DESC LIMIT 5");
        while ($res = mysql_fetch_array($req)) {
            echo $i % 2 ? '<div class="list1">' : '<div class="list2">';
                if (!$res['id']) {
                    // Запрос по гостям
                    $req_g = mysql_query("SELECT `lastdate` FROM `cms_sessions` WHERE `session_id` = '" . md5($res['ip'] . $res['browser']) . "' LIMIT 1");
                    $res_g = mysql_fetch_assoc($req_g);
                    $res['lastdate'] = $res_g['lastdate'];
                }
if (file_exists('../files/users/photo/' . $res['id'] . '_small.jpg'))
  {                  echo '<img src="../files/users/photo/' . $res['id'] . '_small.jpg" width="60" height="60"/><br/>';
 
}
      $arg = array(
        'iphide'    => 1,
        'header'    =>
'<br/>(<i>' . functions::display_date($res['time']) . '</i>)'
    );
            echo functions::display_user($res, $arg);
            
            $text = htmlentities($res['text'], ENT_QUOTES, 'UTF-8');
            $post = bbcode::tags($post);
            $post = str_replace("\r\n","<br />", $post);
            if ($res['user_id']) {
                $post = functions::checkout(mb_substr($res['text'], 0, 250), 1, 1);
                $post = functions::smileys($post, $res['rights'] >= 1 ? 1 :0);
            }
            echo $post;
            if (mb_strlen($res['text']) > 250) {
                echo '<br/><a href="../guestbook/index.php">Read more...</a>';
            }
            echo '</div>';
    $i  ;
        }

    } else {
        echo '<div class="bg">Shoutbox Cleared...</div>';
    }
}

i dont understand to it. The code why not show to user album phot.
if (file_exists('../files/users/photo/' . $res['id'] . '_small.jpg'))
  {                  echo '<img src="../files/users/photo/' . $res['id'] . '_small.jpg" width="60" height="60"/>';
}

Please help me.
.
Менделеев

Try this

if (file_exists('../files/users/photo/' . $user['id'] . '_small.jpg'))
  {                  echo '<img src="../files/users/photo/' . $user['id'] . '_small.jpg" width="60" height="60"/>';
}
.

Not working with ' . $user['id'] . '
sir i am already try with user[id] or res[id] but its not working. I hope in mysql not added call of user[id] or res[id] ?

.
(\/)____o_O____(\/)

$res['user_id'] maybe

.

' . $res['user_id'] . ' not working.

.
Jane
Блиносвёрт ?

$req = mysql_query("SELECT `guest`.*, `guest`.`id` AS `gid`, `users`.`rights`, `users`.`lastdate`, `users`.`sex`, `users`.`datereg`, `users`.`id` as `uid`

FROM `guest` LEFT JOIN `users` ON `guest`.`user_id` = `users`.`id`

WHERE `guest`.`adm`='0' ORDER BY `time` DESC LIMIT 5"

then try $res['uid']

.
(\/)____o_O____(\/)

Jane, `guest`.`id` AS `gid` => not id , not exists image
if they match , it will not be his picture

.
Jane
Блиносвёрт ?

Koenig, we are searching for user id to show his photo

.
fanatos
Менделеев
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/files/users/photo/' . $user_id . '_small.jpg') && $user_id)
echo '<a href="' . $home . '/files/users/photo/' . $user_id . '.jpg"><img src="' . $home . '/files/users/photo/' . $user_id . '_small.jpg" width="60" height="60"/></a>';
.
Менделеев

but for functions::display_user avatar will also appear

Всего: 13