Проблем със извеждане на аватар

draconian

Registered
Здравейте колеги, пиша си сайта и в момента който стигнах до системата за писане на коментари.. запънах. Не мога да изведа Аватара на потребителите които пишат коментари. Моля да ми помогнете

Код:
<?php 
}
$query = mysql_query("SELECT * FROM users WHERE username = '$username'") or die (mysql_error());
$row = mysql_fetch_assoc($query);
if(isset($_POST['chat'])){
$message = addslashes(htmlspecialchars($_POST['message']));
$message = preg_replace('/(\r\n|\n|\r)/','<br />',$message);
$message=preg_replace("/\[b\](.+?)\[\/b\]/s", '<b>$1</b>',$message);
$message=preg_replace("/\[i\](.+?)\[\/i\]/s", '<i>$1</i>',$message);
$message=preg_replace("/\[u\](.+?)\[\/u\]/s", '<u>$1</u>',$message);
$message=preg_replace("/\[s\](.+?)\[\/s\]/s", '<s>$1</s>',$message);
$message=preg_replace("/\[m\](.+?)\[\/m\]/s", '<marquee  onmouseout="this.start()" onmouseover="this.stop()" loop="-1" scrollamount="3" width="30%">$1</marquee>',$message);
$message=preg_replace("/\[quote\](.+?)\[\/quote\]/s", '<div class="quotemain">$1</div>',$message);
$message=preg_replace("/\[quote\=(.+?)](.+?)\[\/quote\]/s", '<div class="Htable" style="width: 630px; height: 20px;"><b>$1</b> каза:</div><div style="margin-top: -5px; border-top: none; -moz-border-radius-topleft:5px; -moz-border-radius-topright:5px;" class="form">$2</div>',$message);
$message=preg_replace("/\[url\](.+?)\[\/url\]/s", '<a href="$1" target="_blank" class="url">$1</a>',$message);
$message=preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/s", '<a href="$1" target="_blank" class="url">$2</a>',$message);
$message=preg_replace("/\[img\](.+?)\[\/img\]/s", '<img src="$1" />',$message);
$message=preg_replace("/\[img\=(.+?)](.+?)\[\/img\]/s", '<a href="$1" target="_blank">$2 - Изображение</a>',$message);
$message=preg_replace("/\[color\=(.+?)\](.+?)\[\/color\]/s", '<span style="color:$1">$2</span>',$message);
$message=preg_replace("/\[size\=(.+?)\](.+?)\[\/size\]/s", '<span style="font-size:$1">$2</span>',$message);
$message=preg_replace("/\[code\](.+?)\[\/code\]/s", '<div style="-moz-border-radius: 5px;-webkit-border-radius: 5px;background: #FFF; padding: 5px; border: 1px solid #DDD; color: teal;"><code>$1</code></div>', $message);
$message = str_replace(":)",'<img src="emoticons/smile.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace(":P",'<img src="emoticons/tong.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace(":D",'<img src="emoticons/bigsmile.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace(":*",'<img src="emoticons/kiss.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace(";(",'<img src="emoticons/crying.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace(";)",'<img src="emoticons/wink.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(wave)",'<img src="emoticons/hi.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(nod)",'<img src="emoticons/nod.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(finger)",'<img src="emoticons/finger.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(mooning)",'<img src="emoticons/mooning.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(wondering)",'<img src="emoticons/wondering.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(yes)",'<img src="emoticons/yes.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(no)",'<img src="emoticons/no.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$message = str_replace("(party)",'<img src="emoticons/party.gif" style="margin-left: 2px;margin-right: 2px">',$message);
$date = date("d.m.Y, H:i");
$rank = $row['rank'];
if($message == NULL){
	header("Location: ".$_SERVER['HTTP_REFERER']."");
}
else {
  $add = mysql_query("INSERT INTO `chatbox` (avtor,message,date) VALUES ('$username','$message','$date')");
  header("Location: chatbox.php");
  }
}
    $tbl_name="chatbox";
	$adjacents = 3;
	$query = "SELECT COUNT(*) as num FROM $tbl_name";
	$total_pages = mysql_fetch_array(mysql_query($query));
	$total_pages = $total_pages[num];
	$targetpage = "chatbox.php";
	$limit = 10;
	$page = $_GET['p'];
	if($page)
		$start = ($page - 1) * $limit;
	else
		$start = 0;

$rl = mysql_query('SELECT COUNT(*) as ctn FROM `chatbox`');
$ruw = mysql_fetch_assoc($rl);
$chatbox = $ruw['ctn'];
if($chatbox == 0){
echo"<div class='error'>Все още нямаме добавени коментари ..</div>";
}
$sel = mysql_query("SELECT * FROM $tbl_name ORDER by id DESC LIMIT $start, $limit") or die (mysql_error());
                      $result = mysql_query("SELECT * FROM users WHERE username = '$username'");
                      $raw = mysql_fetch_assoc($result);
while($row = mysql_fetch_array($sel)){
 echo"<div style='background: #F3F3F3; border: 1px solid #a8a8a8; margin-top: -7px; padding: 5px; padding-bottom: 15px;'>";
if($raw['rank']==4 || $raw['rank'] == 3){
   echo "<a href='del_chat.php?id=$row[id]'><img src='templates/img/icons/x.gif' title='Изтрий коментара' /></a> ";
}
echo"<a href='profile.php?user=$row[avtor]'><b>$row[avtor]</b></a><span style='font: 15px most wazted; float: right;'>#$row[id]</span> на <span style=' font: 10px Comic Sans MS; color: #7c919a;'>$row[date]</span>
<div style='color:#777; margin-top: 5px;'>$row[message]</div></div><br>";
}
	if ($page == 0) $page = 1;
	$prev = $page - 1;
	$next = $page + 1;
	$lastpage = ceil($total_pages/$limit);
	$lpm1 = $lastpage - 1;
	$lastcounter = $lastpage -7;
	$pagination = "";
	if($lastpage > 1)
	{
		$pagination .= "<div class=\"navpage\">";
		// предишния бутон
		if ($page > 1)
			$pagination.= "<a href=\"$targetpage?p=$prev\">«</a>";

		//страници
		if ($lastpage < 5 + ($adjacents * 2))	//не е достатъчно страници, за да се нагърби да го разпада
		{
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"navcurrent\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//достатъчно страници, за да скриете някои
		{
			//достатъчно близо до началото, само крият по-късно страници
			if($page < 1 + ($adjacents * 2))
			{
				for ($counter = 1; $counter < 2 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"navcurrent\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
				}
				$pagination.= "<a href=\"$targetpage?p=$counter\" style='font-weight: bold; color: #666;'>...</a>";
				$pagination.= "<a href=\"$targetpage?p=$lastpage\">$lastpage</a>";
			}
			//в средата; скриете някои отпред и някои обратно
			elseif($lastpage - ($adjacents * 1) > $page && $page > ($adjacents * 1))
			{
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"navcurrent\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
				}			}
			//близо до края, само скрий началото на страницата
			else
			{
				$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
				$pagination.= "<a href=\"$targetpage?p=$lastcounter\" style='font-weight: bold; color: #666;'>...</a>";
				for ($counter = $lastpage - (0 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"navcurrent\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage?p=$counter\">$counter</a>";
				}
			}
		}

		//next button
		if ($page < $counter - 1)
			$pagination.= "<a href=\"$targetpage?p=$next\">»</a>";
		$pagination.= "</div>\n";
	}
?>

Благодаря предварително :cry:
 
Ами никъде не си посочил полетата от DB, но ако предположим, че полето е "avatar"
PHP:
echo"<a href='profile.php?user=$row[avtor]'><b>$row[avtor]</b></a><span style='font: 15px most wazted; float: right;'>#$row[id]</span> на <span style=' font: 10px Comic Sans MS; color: #7c919a;'>$row[date]</span>
<div style='color:#777; margin-top: 5px;'>$row[message]</div></div><br>";
ще бъде
Код:
echo"<a href='profile.php?user=$row[avtor]'><img src='$row[avatar]' alt='$row[avtor]' /></a>
<span style='font: 15px most wazted; float: right;'>#$row[id]</span> 
на <span style=' font: 10px Comic Sans MS; color: #7c919a;'>$row[date]</span>
<div style='color:#777; margin-top: 5px;'>$row[message]</div></div><br>";

Съответно можеш да го преместиш където поискаш.
 
Да беше казал по какъв начин съхраняваш информацията за аватара в БДто... да не сме гадатели.

Ако съхраняваш самия линк просто си правиш <img src=".$row['linka']." />
 
Дааа оправих се !!! Благодаря много! Стана не по начина със $row ами $raw
и се извинявам, че не описах как се съхранява аватара - да със линк е :?:

Може да заключвате темата
 

Back
Горе