[英]mysql database PHP table
我目前在mysql上有一些產品的數據庫,並且正在將它們打印在表中,如您在此處看到的:
好吧,暫時還好,但是...我想將某些圖像設置為產品名稱。 例如,我將放在名稱“ Jeans Fit”(懸停在CSS中)的頂部,它將顯示產品圖像。 如何將某些圖像設置為產品名稱? 不是隨機的,我想選擇每一個,如果您能指導我做這件事的話...
這是我打印表的代碼:
<?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.";
}
您可以嘗試更改:
從:
<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'>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.