我有兩個表Cart_table和product_table。我想要做的就是在車表中顯示最流行的項目,然後將其與自己的產品表,並顯示它在我的 頁面上與變量的匹配什麼我有問題如何比較字符串數組變量與正常字符串變量
String c="",pna="",pty="",ppr="",stock="",imgpath="";
//String myList = new String[10];
int a = 0;
int result = 0,count = 0;
int setres;
int[] arr = new int[100000];
int item_id=0;
data dt=new data();
String item="",cartid="",user="";
String[] prdid = new String[60];
String[] comp = new String[60];
int[] pr_id=new int[50];
//item = "123";
try{
dt.st=dt.cn.createStatement();
//String select="select cartid,user_regid,user_prod_id,quantity from cart_table";
//String select="select cartid,user_regid,user_prod_id,quantity from cart_table";
/*String select="select "+
"cart_table.cartid,cart_table.user_regid,cart_table.user_prod_id,cart_table.quantity,cart_table.add_date,"+
"customer_table.fname,customer_table.email "+
"from cart_table "+
"inner join customer_table "+
"on cart_table.user_regid=customer_table.regid";*/
//String select="select * from cart_table";
String select_match="SELECT user_prod_id, COUNT(*) AS rep "+
"FROM cart_table "+
"GROUP BY user_prod_id "+
"ORDER BY rep desc";
dt.rs=dt.st.executeQuery(select_match);
while(dt.rs.next()){
//String cid=dt.rs.getString("cartid");
//String prid=dt.rs.getString("user_prod_id");
prdid[a] = dt.rs.getString("user_prod_id");
pr_id[a] = dt.rs.getInt("user_prod_id");
String repp = dt.rs.getString("rep");
//String date_add = dt.rs.getString("add_date");
out.println("This is int"+pr_id[a]);
out.println("<br/>"+prdid[a]);
out.println(repp);
a=a+1;
}
out.println("<br/>---------xxx--------");
a=0;
String select3="select "+
"product_table.p_id,product_table.p_type,"+
"product_type.pt_id,"+
"product_table.p_name,product_table.imgpath,product_table.p_price,product_table.stock,product_table.add_date,"+
"product_type.pt_name "+
"from product_table "+
"inner join product_type "+
"on product_table.p_type=product_type.pt_id "+
"order by product_table.add_date desc"+
"";
dt.rs=dt.st.executeQuery(select3);
a = 0;
while(dt.rs.next()){
item_id=dt.rs.getInt("p_id");
String itemm=dt.rs.getString("p_id");
comp[a] = dt.rs.getString("p_id");
String com = dt.rs.getString("p_id");
pna=dt.rs.getString("p_name");
pty=dt.rs.getString("pt_name");
ppr=dt.rs.getString("p_price");
stock=dt.rs.getString("stock");
imgpath=dt.rs.getString("imgpath");
//String comp = prdid[a];
//out.println("<br/>a"+comp+"This is a compare value<br/>");
//out.println("<br/>a"+prdid[a]+"This is an actual value<br/>");
//if(pr_id[a] == item_id)
//if(Arrays.asList(pr_id).contains(item_id))
>
if(prdid[a].equals(com))
{
%>
<li class="span3">
<div class="product-box">
<span class="sale_tag"></span>
<a href="product_detail.jsp?prdid=<%=item_id%>"><img alt="" class="imdis" src="<% out.println(imgpath); %>"></a><br/>
<a href="product_detail.jsp?prdid=<%=item_id%>" class="title"><% out.println(pna); %></a><br/>
<a href="#" class="category"><% out.println(pty); %></a>
<p> <% out.println(item_id); %></p>
<p class="price"><% out.println(ppr); %></p>
</div>
</li> `
<%
}
a = a+1;
}
}
catch(Exception ex){
out.println(ex);
}
我的主要問題是與此代碼
if(prdid[a].equals(com))
{
%>
<li class="span3">
<div class="product-box">
<span class="sale_tag"></span>
<a href="product_detail.jsp?prdid=<%=item_id%>"><img alt="" class="imdis" src="<% out.println(imgpath); %>"></a><br/>
<a href="product_detail.jsp?prdid=<%=item_id%>" class="title"><% out.println(pna); %></a><br/>
<a href="#" class="category"><% out.println(pty); %></a>
<p> <% out.println(item_id); %></p>
<p class="price"><% out.println(ppr); %></p>
</div>
</li> `
<%
}
請先清理你的代碼。 – Gooz
...並將其降至[mcve]。在小型控制檯應用程序中,您可以根本不使用JSP來演示問題。 –