我有个小问题。现在我正在编写一个网站,它连接到mysql数据库。我创建了一个用产品填充的表,这些产品存储在数据库中。每一行都有一个“添加到购物车”按钮,但我如何准确地获取它的特定项目?我已经有了函数addtoCart(string articleName)
,但我不知道如何获得产品的名称。
这是我到目前为止所得到的:
<table id="Products">
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Stock</th>
</tr>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "12345");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT* FROM products WHERE category='shisha'");
while(rs.next()){
int id = rs.getInt("articleID");
String pname = rs.getString("productName");
String description= rs.getString("description");
float price = rs.getFloat("price");
int stock = rs.getInt("stock");
%>
<tr>
<td><%out.print(id);%></td>
<td><%out.print(pname);%></td>
<td><%out.print(description);%></td>
<td><%out.print(price);%></td>
<td><%out.print(stock);%></td>
<td> </td>
<td><input type="text" placeholder="How much ?" name="quantity" required> </td>
<td> <input class="button" type = "submit" value="Add to cart"> </td>
</tr>
<%
}
%>
</table>
因此,它为每个产品生成一行,并具有自己的按钮……我想调用函数addtoCart(string articleName)
,但是如何获得按钮所在行的产品名称呢?
https://stackoverflow.com/questions/51158001
复制相似问题