0
<?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>";

}

}

        }

}

?>

I would like some help putting the user image into the echo section of this code. I am not exactly sure how to do this so that it puts the image on the correct line of the search. Any advice would be greatly appreciated. Below is the line of code that I am referring too. Thanks.

while($results_row = mysql_fetch_assoc($search)) {

echo '', "' width= 50px height=50px>", $results_row['username'], '';

Musa
  • 96,336
  • 17
  • 118
  • 137
Steven
  • 180
  • 3
  • 3
  • 12
  • Also, use prepared statements when building SQL queries. Check this post to see why `mysql_real_escape_string` won't protect your database from SQL injection - http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string – laurent Jul 10 '12 at 01:45

4 Answers4

1

I don't see $image defined anywhere in your code, so I'm going to assume the image is being pulled from the database.

If that's the case then you'll want to do something like this:

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>';
}
Marcus Recck
  • 5,075
  • 2
  • 16
  • 26
0

just write:

..."<img src='/image/<?php echo $image; ?>' width='50' height='50'>", ...

but are you sure that 50x50 is suitable? you might want to set only width=50 and leave the browser to set height accordingly.

0
$image = 'someImage.png';    
echo '<div data-theme="a"><strong>', "<img src='/image/{$image}' width= 50px height=50px>", $results_row['username'],  '</strong></div>';
Anton Kucherov
  • 307
  • 1
  • 6
0

You would want something like this:

<?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
}
?>

A few things to check though:

  • dont use tags to wrap tags. They're generally used for text only
  • You're not selecting any image on your query.
  • don't use echo to output html its ugly.
  • don't use GET.
  • Use prepared statements (PDO or mysqli) to protect from mysql injection.
Wern Ancheta
  • 22,397
  • 38
  • 100
  • 139