mysql数据库PHP表

mysql数据库PHP表,php,mysql,html-table,Php,Mysql,Html Table,我目前在mysql上有一个数据库,其中包含一些产品,我正在将它们打印到一个表中,如您所见: 现在还可以,但是。。。我想将某些图像设置为产品名称。 例如,我会在css中的名称Jeans Fit hover的顶部,它会显示产品图像。如何将某些图像设置为产品名称?不是随机的,我想选择每一个,如果你能在这个问题上指导我 以下是我打印表格的代码: <?php // to prevent undefined index notice $action = isset($_GET['action'])

我目前在mysql上有一个数据库,其中包含一些产品,我正在将它们打印到一个表中,如您所见:

现在还可以,但是。。。我想将某些图像设置为产品名称。 例如,我会在css中的名称Jeans Fit hover的顶部,它会显示产品图像。如何将某些图像设置为产品名称?不是随机的,我想选择每一个,如果你能在这个问题上指导我

以下是我打印表格的代码:

<?php

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

if($action=='add'){
    echo "<div>" . $name . " foi adicionado ao carrinho</div>";
}

if($action=='exists'){
    echo "<div>" . $name . " já existe no carrinho</div>";
}

require "libs/DbConnect.php";


// page is the current page, if there's nothing set, default is page 1
$page = isset($_GET['page']) ? $_GET['page'] : 1;

// set records or rows of data per page
$recordsPerPage = 6;

// calculate for the query LIMIT clause
$fromRecordNum = ($recordsPerPage * $page) - $recordsPerPage;
// select all data
$query = "SELECT 
            id, name,price 
        FROM 
            products
        ORDER BY 
            id 
        LIMIT 
            {$fromRecordNum}, {$recordsPerPage}";

            /*
            page and its LIMIT clause looks like:
            1 = 0, 5
            2 = 5,10
            3 = 10,15
            4 = 15, 20
            5 = 20, 25
            */

$stmt = $con->prepare( $query );
$stmt->execute();

//this is how to get number of rows returned
$num = $stmt->rowCount();


if($num>0){
    echo "<table border='0'>";//start table

        // our table heading
        echo "<tr>";
            echo "<th class='textAligncenter'>Nome Produto</th>";
            echo "<th>Preço (EUR)</th>";
            echo "<th>Acção</th>";
        echo "</tr>";

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

            //creating new table row per record
            echo "<tr>";
                echo "<td>{$name}</td>";
                echo "<td class='textAlignRight'>{$price}</td>";
                echo "<td class='textAlignCenter'>";
                    echo "<a href='addToCart.php?id={$id}&name={$name}' class='customButton'>";
                        echo "<img src='images/add-to-cart.png'  class='imagem2'title='Adicionar ao carrinho' />";
                    echo "</a>";
                echo "</td>";
            echo "</tr>";
        }

    echo "</table>";
}

// no products in the database
else{
    echo "No products found.";
}
您可以尝试更改:

发件人:

致:


但这只会给我一个有效的产品,对吧??:我想是的,好吧,看看这个链接,我想它会有帮助:你了解php吗?我真的对这个问题很生气,xD和我的php都不是很好。这个链接对我的代码不起作用,我想兄弟。是否可以根据我的产品id添加类似的图像?。将图像X设置为id为5的产品,等等。这样行吗?我有逻辑,但在php:s中,将其转换为代码对我来说很难
<a href='addToCart.php?id={$id}&name={$name}' class='customButton'>
<a href='addToCart.php?id={$id}&name={$name}' onmouseover="document.images['image'].src='images/your_image.jpg' class='customButton'>