我不知道如何把一個SQL查詢到一個變量像這樣的:PHP/SQL - SQL結果設置爲一個列表
$in = "Lambo 1; Trabant 2; Car 3;";
$result=mysqli_query($conn,$sql_query);
查詢當前回來了Lambo 1; Trabant 2; Car 3;
,但我將如何改變成在$?彷彿我目前正在通過另一FUNC運行它,我得到explode() expects parameter 2 to be string,
全碼:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$host = 'localhost';
$username = '';
$password = '';
$database = '';
$conn = mysqli_connect($host,$username,$password,$database);
$SteamID = "STEAM_0:0:81010017";
$sql_query="SELECT _Inventory FROM Players Where _SteamID='$SteamID'";
$result=mysqli_query($conn,$sql_query);
$in = $result;
foreach (explode(";", $in) as $element) {
$element = trim($element);
if (strpos($element, " ") !== false) {
list($car, $number) = explode(" ", $element);
echo $car;
}
}
?>
你嘗試過使用mysql_fetch_array(),而不是sql_query()? – bMalum
仍然不起作用 – PaulB3434
看到我的評論提示 - 這應該工作。 – bMalum