使用echo [duplicate]在我的页面中显示图像

问题描述:

This question already has an answer here:

this is code of the page that I will get the image from(work perfectly)

<?php
    ob_start();
    session_start();
    include('connect.php');

    $id = $_GET['id'];
    $query = mysql_query("SELECT * FROM news WHERE id=$id");
    $row = mysql_fetch_assoc($query);

    header("Content-type: image/jpeg");
    echo $row['image'];
?>

and this is my page that i get the image to in

<?php
    ob_start();
    session_start();
    include('includes/connect.php');
    include('includes/phpCodes.php');

    $id = $_GET['id'];

    function showNews() {
        $data = array( 'id' => $id );
        $base = "includes/getImage.php";
        $url = $base. "?" . "id=36";
        echo $url;
        echo '<img src=includes/getImage.php class="newsImage">';
        echo '<h1><p class="subjecTitle">هنا العنوان</p></h1>   
                 <div class="newsContent">
                    hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi
             </div>
        ';
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <title>عينٌ على الحقيقة</title>

        <meta charset="utf-8">

        <link rel="stylesheet" type="text/css" href="css/mainstyle.css">
        <link rel="stylesheet" type="text/css" href="css/showstyle.css">
        <script lang="javascript">
            function logout( myFrame ) {
                myFram.submit();
            }
        </script>
    </head>
    <body>
        <div class="wrapper">
            <?php headerCode(); ?>
            <div class="content" dir="rtl">
                <?php showNews(); ?>
            </div>
        </div>
    </body>
</html> 

i think my wrong is in , can someone tell me how can I solve it?, sorry for my bad english

</div>

Cleared it up for you:

echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';

Should 100% work (if the $id param has a value of course).

Update to fix the missing $id var:

    <?php
        ob_start();
        session_start();
        include('includes/connect.php');
        include('includes/phpCodes.php');

        $id = $_GET['id'];

        function showNews(){
            $id = $_GET['id'];
            $base = "includes/getImage.php";
            $url = $base. "?" . "id=36";
            echo $url;
            echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';

            echo '
                <h1><p class="subjecTitle">??? ???????</p></h1> 
                <div class="newsContent"></div>
            ';
        }
    ?>

Change :

echo ' <img src=includes/getImage.php class="newsImage">';

To :

echo ' <img src="includes/getImage.php?id='.$id.'" class="newsImage">';

Please note src has " and also make sure that includes/getImage.php return a image path

why are you using two different pages? put both code in single page and simply do this

 <img src=includes/<?php echo $row['image']; ?> class="newsImage">