php - 使用 php 从 mysql 表中获取数据并做出本机反应
问题描述
我想显示 MySQL 表中使用 PHP 处理并做出本机反应但不提供响应且不显示任何错误消息的数据。如果我用浏览器运行的 PHP 脚本会如下所示:
[
{"group":"1","name":"Soy Souce A"},
{"group":"2","name":"Soy Souce B"},
{"group":"3","name":"Chili Tomato Souce"},
{"group":"4","name":"Vinegar"},
{"group":"5","name":"Syrup"}
]
这是屏幕截图显示:
我的问题 :
- 为什么数据不能显示
- 如截屏一样,为什么会出现3个标题,标题2是导航,如何消除标题1和3请帮助我克服它,谢谢
这是反应原生脚本
import React, { Component } from 'react';
import DatePicker from 'react-native-datepicker'
import { View, Text, TouchableOpacity, FlatList } from 'react-native';
import { createStackNavigator } from 'react-navigation-stack'
import { createAppContainer } from 'react-navigation'
import Icon from 'react-native-vector-icons/MaterialIcons';
import { Item, } from 'native-base';
class DataSearch extends React.Component {
constructor(props){
super(props)
this.state = {
date:"",
isLoading: false
}
}
componentDidMount() {
var that = this;
var date = new Date().getDate();
var month = new Date().getMonth() + 1;
var year = new Date().getFullYear();
that.setState({
date: date + '-' + month + '-' + year,
});
}
DataShowProcess = () =>{
const { date } = this.state ;
this.setState({
dataSource: [],
isLoading: true
});
fetch('https://example.com/item_group.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
dateSearch: date,
})
})
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson
});
this.props.navigation.navigate('Second', this.state.dataSource);
})
.catch((error) => {
console.error(error);
});
}
render(){
return (
<View>
<DatePicker
style={{width: 200}}
date={this.state.date}
mode="date"
placeholder="select date"
format="DD-MM-YYYY"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
customStyles={{
dateIcon: {
position: 'absolute',
left: 200,
top: 0,
marginLeft: 0
},
dateInput: {
marginLeft: 100
},
}}
onDateChange={(date) => {this.setState({date: date})}}
/>
<TouchableOpacity
style={{ alignItems: 'center'}}
onPress={this.DataShowProcess}
>
<Icon name='search' size={35} color='black'/>
</TouchableOpacity>
</View>
)
}
}
class DataShow extends React.Component {
render(){
const { navigation } = this.props;
return (
<View style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.responseJson}
renderItem={({item}) => <Text>{item.group}, {item.name}</Text>}
keyExtractor={({id}, index) => id}
/>
</View>
)};
}
const RootStack = createStackNavigator({
First: DataSearch,
Second: DataShow,
});
export default createAppContainer(RootStack);
解决方案
推荐阅读
- wireshark - 成功 DTLS 解密后无法在 Wireshark 中解码 COAP 数据包
- drools - 在 Drools 中获取相似的对象
- regression - catboost 回归/CatBoostRegressor 上的销售预测错误
- mysql - 在 MySQL 中使用名称空间创建表
- php - Ajax 返回状态码 0 但脚本仍在工作
- java - 如何使用 JAXBContext 和 Marshaller 在 Web 浏览器上显示 XML
- regex - Prometheus 警报 - 按百分比而不是绝对请求
- python - Pandas 将单列数据框与另一个多列数据框合并
- php - Laravel 8,异常,无法调试
- excel - Excel 公式 - 通过忽略另一列中的重复值来聚合行