我想將我的數據庫表中的一列存儲在一個數組中,這樣我就可以將它與我擁有的數組進行比較。我只從表格中選擇一列,並存儲所有行。我設法這樣做,但在2D數組,但是當比較2D數組到我的1D數組時,我得到一個錯誤。所以請幫助我將它轉換爲1d數組或從開始,如果我可以將數據存儲在1d數組中。從1D數組中的數據庫存儲數據不是2d
$array = array();
$serviceId = "SELECT service_id FROM servicesorders WHERE order_id = '$orderId'";
$resultId = mysqli_query($connection, $serviceId) or die(mysqli_error($connection));
while ($serviceIdfinal = mysqli_fetch_assoc($resultId)) {
$array[] = $serviceIdfinal; //the array I used to store the data
}
var_dump($array);
$isCheckedstring = $_POST['show'];
$isCheckedarray = str_split($isCheckedstring, 4); // the array I want to compare the stored data with
var_dump($isCheckedarray);
兩個數組的後續代碼var_dump如下:
array(
[0]=> array(
["service_id"]=> "1"
)
[1]=> array(
["service_id"]=> "7"
)
[2]=> array(
["service_id"]=> "11"
)
)
而且
array(
[0]=>"0011"
[1]=>"0012"
)
[小博](http://bobby-tables.com/)說** [你的腳本是在對SQL注入攻擊的風險(HTTP://計算器.COM /問題/ 60174 /何燦I-防止-SQL注入式-PHP)**。瞭解[MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)的[Prepared Statements](準備語句)(http://en.wikipedia.org/wiki/Prepared_statement)。即使** [轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)**是不安全的! – GrumpyCrouton
和你的問題是什麼? –
@GrumpyCrouton在很長一段時間裏都沒有看到過小笨蛋 –