please help
how do i echo the images to display since its only displaying the code on the database table e.g image10.jpg.
on line 60

thanx

<?php


$page_title="Products";


// to prevent undefined index notice
$action = isset($_GET['action']) ? $_GET['action'] : "";
$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : "1";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$pdesc = isset($_GET['pdesc']) ? $_GET['pdesc'] : "";
$imgname = isset($_GET['imgname']) ? $_GET['imgname'] : "";




if($action=='added'){
    echo "<div class='alert alert-info'>";
        echo "<strong>{$name}</strong> was added to your cart!";
    echo "</div>";
}

if($action=='exists'){
    echo "<div class='alert alert-info'>";
        echo "<strong>{$name}</strong> already exists in your cart!";
    echo "</div>";
}

$query = "SELECT id, name, pdesc, imgname, price FROM products ORDER BY name";
$stmt = $con->prepare( $query );
$stmt->execute();

$num = $stmt->rowCount();

if($num>0){

    //start table
    echo "<table class='table table-hover table-responsive table-bordered'>";

        // our table heading
        echo "<tr>";
            echo "<th class='textAlignLeft'>Product Name</th>";
            echo "<th>Product Description</th>";
            echo "<th>Image </th>";           
            echo "<th>Price </th>";
            echo "<th>Action</th>";
        echo "</tr>";

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            extract($row);

            //creating new table row per record
            echo "<tr>";
                echo "<td>";
                    echo "<div class='product-id' style='display:none;'>{$id}</div>";
                    echo "<div class='product-name'>{$name}</div>";

                echo "</td>";
                echo "<td>{$pdesc}</td>";
                echo "<td>{$imgname}</td>";

                echo "<td>&#36;{$price}</td>";
                echo "<td>";
                    echo "<a href='add_to_cart.php?id={$id}&name={$name}' class='btn btn-primary'>";
                        echo "<span class='glyphicon glyphicon-shopping-cart'></span> Add to cart";
                    echo "</a>";
                echo "</td>";
            echo "</tr>";
        }

    echo "</table>";
}

// tell the user if there's no products in the database
else{
    echo "No products found.";
}


?>

Recommended Answers

All 3 Replies

Replace

echo "<td>{$imgname}</td>";

with

echo "<td><img src='path_to_image_folder/{$imgname}'></td>";

thanx but i had tried that and it gives me an error:
Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\wamp\www\redwines.php on line 105

echo "<img src = 'cms/pages/images/{$img[1]}'>";

this worked guess i was putting the quotes wrong

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.