在mysql命令的mysql查询结果中
language id language name
1 English
2 Hindi
3 Russian
$language_name =$conn->prepare("SELECT language_id, language_name FROM language_master");
$language_name->setFetchMode(PDO::FETCH_BOTH);
$language_name->execute();
$language_name = $language_name->fetch();
如何在php中打印/回显所有语言和ID?就像在桌子上一样。
感谢您的帮助。
答案 0 :(得分:0)
您可以使用
var_dump($language_name);
或
print_r($language_name);
打印整个数组。
修改强>
所以你可以用作foreach-loop:
foreach($language_name as $key => $value)
{
echo $key . ' => ' . $value;
echo "</br>";
}
答案 1 :(得分:0)
while($row = $language_name->fetch()) {
$allRows[] = $row;
}
然后在php
foreach($allRows as $value){
echo $value['language_id'];
}
答案 2 :(得分:0)
如果我能帮到你,你想在表中显示结果..使用循环来获取数据。 e.g
<?php
if(!empty($language_name)):
$i = 0;
foreach($language_name as $rows):
$i++;
echo $rows['language_id']; //for the language id
echo $rows['language_name ']; //for language name
endforeach;
endif;
?>