我有SQL查询:
SELECT countryCode FROM itins_countries WHERE (itinID = 5);
$countriesIndex = mysql_fetch_array($countriesQuery);
现在,在我的代码的另一个艺术中,我想运行" $ countriesIndex"并打印它包含的所有值(" countryCode");
我该怎么做?
答案 0 :(得分:1)
while($row = mysql_fetch_array($countriesQuery)){
echo $row['column_name'];
///same for other columns
}
你可以使用while循环来循环直到所有数组元素都被打印
答案 1 :(得分:0)
试试这个......
echo "<pre>";print_r($countriesIndex);
答案 2 :(得分:0)
不推荐使用mysql_connect ...您可以使用mysqli_connect。
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
mysqli_set_charset($mysqli, "utf8");
$sql = "SELECT countryCode FROM itins_countries WHERE (itinID = 5)";
$result = mysqli_query($mysqli, $sql);
$countries = [];
while($row = $result->fetch_assoc())
{
$users_arr[] = $row;
}
$result->close();
print_r($users_arr);