<?php
require 'db.php';
include_once("header.php");
include_once("functions.php");
include_once("profile.php");
if(isset($_POST['search_term'])){
$search_term = mysql_real_escape_string(htmlentities ($_POST['search_term']));
if(!empty($search_term)){
$search = mysql_query("SELECT `username`,`id` FROM `users` WHERE `username` LIKE '%$search_term%' and `business` <> 'business'");
$result_count = mysql_num_rows($search);
$suffix = ($result_count != 1) ? 's' : '';
echo '<div data-theme="a">Your search for <strong>' , $search_term ,'</strong> returned <strong>', $result_count,' </strong> record', $suffix, '</div>';
while($results_row = mysql_fetch_assoc($search)){
echo '<div data-theme="a"><strong>', "<img src='/image/<?php echo $image; ?>' width= 50px height=50px>", $results_row['username'], '</strong></div>';
$following = following($_SESSION['userid']);
if (in_array($key,$following)){
echo ' <div action= "action.php" method="GET" data-theme="a">
<input type="hidden" name="id" value="$key"/>
<input type="submit" name="do" value="follow" data-theme="a"/>
</div>';
}else{
echo " <div action='action.php' method='GET' data-theme='a'>
<input type='hidden' name='id' value='$key'/>
<input type='submit' name='do' value='follow' data-theme='a'/>
</div>";
}
}
}
}
?>
我想帮助将用户图像放入此代码的echo部分。我不确定如何做到这一点,以便它将图像放在搜索的正确行上。任何建议将不胜感激。下面是我所指的代码行。感谢。
while($ results_row = mysql_fetch_assoc($ search)){
回声'', “'宽度= 50px height = 50px&gt;“,$ results_row ['username'],'';
答案 0 :(得分:1)
我没有在代码中的任何地方看到$image
,因此我假设图像是从数据库中提取的。
如果是这种情况,那么你会想做这样的事情:
while($results_row = mysql_fetch_assoc($search)){
echo '<div data-theme="a"><strong><img src="/image/'.$results_row['image'].'" style='width:50px;height:50px' />'.$results_row['username'].'</strong></div>';
}
答案 1 :(得分:0)
只写:
..."<img src='/image/<?php echo $image; ?>' width='50' height='50'>", ...
但您确定 50x50 是否合适?您可能只想设置width=50
并让浏览器相应地设置高度。
答案 2 :(得分:0)
$image = 'someImage.png';
echo '<div data-theme="a"><strong>', "<img src='/image/{$image}' width= 50px height=50px>", $results_row['username'], '</strong></div>';
答案 3 :(得分:0)
你会想要这样的东西:
<?php
while($results_row = mysql_fetch_assoc($search)){
?>
<div data-theme="a">
<img src="/image/<?php echo $image; ?>" width="50px" height="50px">
<strong>
<?php echo $results_row['username']; ?>
</strong>
</div>
<?php
}
?>
要检查的一些事情: