我有一个理想的搜索框,可以搜索给定列表中的项目。我的搜索工作正常,问题是当我在搜索框中输入内容进行搜索时,它会给我结果,但我的搜索框会变空。 例如,如果我在搜索框中搜索“电子产品”,它会给我电子产品的结果,但我的搜索框变空。当它给我结果时,应该用“电子”写。 可能,我应该使用GET方法而不是这样吗?
以下是我的搜索代码:
<form action="" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" value="Submit" />
</form>
if (!empty($_REQUEST['term']))
{
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM category WHERE cat_name LIKE '%" . $term . "%' or parent LIKE '%" . $term . "' or cat_status LIKE '%" . $term . "'";
}
$r_query = mysql_query($sql);
if ($r_query > 1)
{
$dynamicList="";
while ($row = mysql_fetch_array($r_query))
{
// $cat_id=;
/*$dynamicList .= '
<img style="border:#666 1px solid;" src="../storeadmin/category/thumbs/' . $row['cat_id'] . '.jpg" width="77" />';*/
echo "<tr bgcolor=''>";
echo "<td>" . $row['cat_id'] . "</td>";
echo "<td><img style='border:#666 1px solid;' width='70' src='http://localhost/jaymin/My%20Store/storeadmin/category/thumbs/". $row['cat_id'].".jpg' /></td>";
//echo "<td>".$dynamicList."</td>";
echo "<td>" . $row['cat_name'] . "</td>";
echo "<td>" . $row['parent'] . "</td>";
echo "<td>" . $row['cat_status'] . "</td>";
echo "<td><a href='categoryylisting_edit.php?id=" . $row['cat_id'] . "'>Edit</a></td>";
echo "<td><a name='delete' href='categoryylisting_edit.php?id=" . $row['cat_id'] . "'>Delete</a></td><tr>";
echo "</tr>";
}
}
else {
echo "Nothing should be displayed";
}
?>
</table>
答案 0 :(得分:0)
将您的代码更改为
import React, {
Component
} from 'react';
import {
StyleSheet,
Text,
Dimensions,
Navigator,
StatusBar
} from 'react-native';
import SideMenu from 'react-native-side-menu';
import Icon from 'react-native-vector-icons/Ionicons';
import { AppRoutes } from '../../../common/config';
import {
SideMenuContent,
Button
} from '../../components';
import Home from '../home';
import AppState from '../appState';
const SCREEN_WIDTH = Dimensions.get('window').width;
class App extends Component {
constructor(props) {
super(props);
this.init();
}
init() {
this.state = {
sideMenuOpened: false
};
}
openSideMenu() {
this.setState({
sideMenuOpened : false
});
}
closeSideMenu() {
if (this.state.sideMenuOpened) {
this.setState({
sideMenuOpened : false
});
}
}
toggleSideMenu() {
this.setState({
sideMenuOpened: !this.state.sideMenuOpened
});
}
updateSideMenuState(isOpened) {
this.setState({
sideMenuOpened: isOpened
});
}
navigate(route) {
const routeStack = [].concat(this.refs.navigator.getCurrentRoutes());
const previousRouteId = routeStack[routeStack.length - 1].id;
if (route.id !== previousRouteId) {
this.refs.navigator.replace(route);
}
if (this.state.sideMenuOpened) {
this.closeSideMenu();
}
}
renderScene(route, navigator) {
switch (route.id) {
case 1:
const route1 = AppRoutes.getRouteFromRouteId(1);
return (
<Home
ref={route1.refView}
navigator={navigator}
navigate={(toRoute)=>this.navigate(toRoute)}
/>
);
case 2:
const route2 = AppRoutes.getRouteFromRouteId(2);
return (
<AppState
ref={route2.refView}
navigator={navigator}
navigate={(toRoute)=>this.navigate(toRoute)}
/>
);
default:
return (
<Home
ref={route1.refView}
navigator={navigator}
navigate={(toRoute)=>this.navigate(toRoute)}
/>
);
}
}
renderRouteMapper() {
const routes = AppRoutes.getAllRoutes();
return {
Title : (route, navigator, index, navState) => {
const currentRouteId = navState.routeStack[index].id;
return (
<Text style={styles.titleNavText}>
{routes[currentRouteId - 1].navbar.navBarTitle}
</Text>
);
},
LeftButton : (route, navigator, index, navState) => {
const currentRouteId = navState.routeStack[index].id;
return (
<Button
style={styles.leftNavButton}
onPress={(e)=>this.toggleSideMenu(e)
}>
<Icon
name={routes[currentRouteId - 1].navbar.navBarLeftIconName}
size={32}
color={'#333333'}
/>
</Button>
);
},
RightButton : (route, navigator, index, navState) => {
return null;
}
};
}
render() {
StatusBar.setBarStyle('light-content', true);
const DEFAULT_ROUTE = { id: 1, refView: 'HomeView' };
return (
<SideMenu
menu={<SideMenuContent
backGndColor="#ECECEC"
navigate={(route)=>this.navigate(route)}
/>}
isOpen={this.state.sideMenuOpened}
onChange={(isOpened) => this.updateSideMenuState(isOpened)}
bounceBackOnOverdraw={false}
openMenuOffset={SCREEN_WIDTH * 0.8}
>
<Navigator
ref="navigator"
initialRoute={ DEFAULT_ROUTE }
sceneStyle={ styles.navigator }
renderScene={(route, navigator)=>this.renderScene(route, navigator)}
configureScene={()=>Navigator.SceneConfigs.FadeAndroid}
navigationBar={
<Navigator.NavigationBar
routeMapper={this.renderRouteMapper()}
style={styles.navBar}
/>
}
/>
</SideMenu>
);
}
}
const styles = StyleSheet.create({
navigator: {
backgroundColor: '#fff',
borderLeftWidth: 0.5,
borderLeftColor: '#F1F1F1',
},
navBar: {
backgroundColor: '#fff',
borderWidth: 0.5,
borderColor: '#F1F1F1'
},
leftNavButton : {
flex : 1,
flexDirection : 'column',
alignItems : 'center',
marginTop : 4,
paddingTop : 0,
paddingBottom : 10,
paddingLeft : 20,
paddingRight : 10
},
rightNavButton : {
flex : 1,
flexDirection : 'column',
alignItems : 'center',
marginTop : 4,
paddingTop : 6,
paddingBottom : 10,
paddingLeft : 10,
paddingRight : 10
},
titleNavText : {
marginTop : 14,
color : '#333333'
}
});
export default App;
而不是
Search: <input type="text" name="term" value="<?php echo @$_REQUEST['term']; ?>" /><br />
答案 1 :(得分:0)
试试这个,
<input type="text" name="term" value="<?php if(isset($_POST['term'])){ echo $_POST['term']; } ?>"/>
如果您想在url
使用GET
代替POST
之类的话,
<form action="" method="get">
Search: <input type="text" name="term" value="<?php if(isset($_GET['term'])){ echo $_GET['term']; } ?>" /><br />
<input type="submit" value="Submit" />
</form>
答案 2 :(得分:0)
这是因为您提交表单并在表单提交后文本框值消失。要克服这个尝试:
<input type="text" name="term" value="<?php if(isset($_POST['term'])){ echo $_POST['term']; } ?>"/>