我想知道这是否是连接许多动态变量并将它们存储到一个变量中的正确方法?动态变量包含HTML。根据早期的代码,其中一些可能不包含任何内容。
还是有其他选择吗?
let navController = UINavigationController(rootViewController: yourController)
navController.view.backgroundColor = UIColor.blue
// If you also want to set the navigation bar background color:
navController.navigationBar.backgroundColor = UIColor.blue
答案 0 :(得分:1)
你应该做
$specialproductmsg = $garminmsg . $studdybuddymsg . $baroncoursemsg . $fircoursemsg . $pilotworkshopmsg . $cfirenewalmsg . $flightsimmsg . $xplane11msg . $ltfcoursemsg;
所有内容都会存储在$specialproductmsg
要连接,请不要在变量之间使用.=
。
您可以看到更多here
答案 1 :(得分:1)
您可以将它们存储在一个变量中以开始。
而不是像package com.jspiders.studentsapp.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mysql.jdbc.Driver;
public class Deleteservlet extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
int regno=Integer.parseInt(req.getParameter("regno"));
System.out.println("mime type set");
Connection con = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
int count,count1,count2 =0;
try {
Driver driverref = new Driver();
DriverManager.registerDriver(driverref);
String dburl = "jdbc:mysql://localhost:3306/Becm145_DB?user=root&password=root";
con = DriverManager.getConnection(dburl);
String query = "delete from students_info where regno=?";
String query1 = "delete from students_otherinfo where regno=? ";
String query2=" delete from guardian_info where regno=? ";//garbage collector call finalize before garbage collected when the space is full or reach level at that time garbage call finalize and then collected
pstmt = con.prepareStatement(query);
pstmt.setInt(1,regno);
count = pstmt.executeUpdate();
pstmt1 = con.prepareStatement(query1);
pstmt1.setInt(1,regno);
count1 = pstmt1.executeUpdate();
pstmt2 = con.prepareStatement(query2);
pstmt2.setInt(1,regno);
count2 = pstmt2.executeUpdate();
if(count == 1 && count1 == 1 && count2 == 1)
{
out.println("<h1>profile ,is deleted</h1>");
}
else
{
out.println("<h1>failed in deleting profile</h1>");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("close all jdbc objects");
}
try {
if (con != null) {
con.close();
}
if (pstmt != null) {
pstmt.close();
}
if (rs != null) {
rs.close();
}
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
和$garminmsg
这样的所有单独变量,您可以将动态HTML字符串分配给数组的不同键,如
$studdybuddymsg
您可以使用$html['garminmsg']
$html['studdybuddymsg']
// etc.
与$html['garminmsg']
进行相同的操作,以及何时输出(或将整个内容分配给另一个)变量)你可以使用像
$garminmsg
或
$specialproductmsg = implode('', $html);
并放弃所有混乱的连接。
答案 2 :(得分:0)
您可以使用.
在PHP中连接。
//assuming first initialization, use = to assign, . to concatenate vars
$specialproductmsg = $garminmsg.$studdybuddymsg.$baroncoursemsg;
//since init already, append additional concatenated vars
$specialproductmsg .= $fircoursemsg.$pilotworkshopmsg.$cfirenewalmsg;
$specialproductmsg .= $flightsimmsg.$xplane11msg.$ltfcoursemsg;
为了便于阅读,我将其拆分为三行。 .=
在.
连接时附加{。}}。
.=
等同于var =
本身与其他内容的连接:
$foo .= $bar;
//is equivalent to
$foo = $foo.$bar;