现在MySQL结果中的所有列都转换为JSON并在屏幕上打印出来。我想在屏幕上只打印两列$row['name']
和$row['gender']
。任何想法的人
include('connect-db.php');
$result = mysql_query("SELECT * FROM patientvaccinedetail")
while($row = mysql_fetch_assoc( $result)) {
print_r(json_encode($row));}
答案 0 :(得分:2)
Application.SendKeys("%s")
答案 1 :(得分:1)
这是我从表中获取所有内容并仅显示两个值的解决方案....
include('connect-db.php');
$result = mysql_query("SELECT * FROM patientvaccinedetail") //getting all the fields
while($row = mysql_fetch_assoc( $result)) {
$data = array('name' => $row['name'] , 'gender' => $row['gender']); //get the two values into one array
print_r(json_encode($data)); //printing the name and gender
}
如果你只想在这里得到另外两个字段...
include('connect-db.php');
$result = mysql_query("SELECT name,gender FROM patientvaccinedetail") //getting two the fields
while($row = mysql_fetch_assoc( $result)) {
print_r(json_encode($row)); //printing the name and gender
}
答案 2 :(得分:0)
如果您想要所有数据,但只需要打印名称&性别然后..创建一个单独的阵列&分配名称&性别...
$data_array = array();
while($row = mysql_fetch_assoc( $result)) {
array_push($data_array,array("name"=>$row['name'],"gender"=>$row['gender']);
}
print_r(json_encode($data_array));
答案 3 :(得分:0)
include('connect-db.php');
$result = mysql_query("SELECT name,gender FROM patientvaccinedetail")
while($row = mysql_fetch_assoc( $result)) {
print_r(json_encode($row));}