sopranolv Posted January 30, 2015 Share Posted January 30, 2015 (edited) Hello,can anyone help me create members search script? here is image example here is 'users 'table `id` int(11) NOT NULL auto_increment, `age` varchar(200) collate utf8_unicode_ci NOT NULL, `city` varchar(200) collate utf8_unicode_ci NOT NULL, `username` varchar(30) collate utf8_unicode_ci NOT NULL, `password` varchar(150) collate utf8_unicode_ci NOT NULL, `salt` varchar(10) collate utf8_unicode_ci NOT NULL, `mgroup` int(3) NOT NULL, `email` varchar(100) collate utf8_unicode_ci NOT NULL, `ip` varchar(15) collate utf8_unicode_ci NOT NULL, `posts` int(11) NOT NULL, `date_joined` varchar(25) collate utf8_unicode_ci NOT NULL, `logged_in` int(1) NOT NULL default '0', `last_action_time` int(25) NOT NULL, `signature` text collate utf8_unicode_ci NOT NULL, `avatar` varchar(300) collate utf8_unicode_ci NOT NULL default 'default', `what_is_doing` varchar(30) collate utf8_unicode_ci NOT NULL, `what_is_doing_id` varchar(100) collate utf8_unicode_ci NOT NULL, `name` varchar(200) collate utf8_unicode_ci NOT NULL, `website` varchar(200) collate utf8_unicode_ci NOT NULL, `title` varchar(150) collate utf8_unicode_ci NOT NULL, `rank_pips` int(11) NOT NULL, `friends` tinytext collate utf8_unicode_ci NOT NULL, `blocks` tinytext collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; Please help me? Edited January 30, 2015 by sopranolv Quote Link to comment https://forums.phpfreaks.com/topic/294264-can-anyone-help-me-create-search-script/ Share on other sites More sharing options...
QuickOldCar Posted January 30, 2015 Share Posted January 30, 2015 The purpose of this forum is to help people with their existing code, not create it. Do you have any code right now? You need retrieve the POST or GET data from that form connect to the database do an sql query using WHERE and BETWEEN using the POST dynamic values return the results in a while loop http://php.net/manual/en/book.pdo.php http://php.net/manual/en/book.mysqli.php http://php.net/manual/en/mysqli-result.fetch-assoc.php http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between Quote Link to comment https://forums.phpfreaks.com/topic/294264-can-anyone-help-me-create-search-script/#findComment-1504341 Share on other sites More sharing options...
Solution QuickOldCar Posted January 30, 2015 Solution Share Posted January 30, 2015 I had a little time to spare Edit to your database credentials and should see it working <?php //POST minimum age if (isset($_POST['minage']) && ctype_digit(trim($_POST['minage']))) { $minage = trim($_POST['minage']); } else { $minage = "1"; //default } //POST maximum age if (isset($_POST['maxage']) && ctype_digit(trim($_POST['maxage']))) { $maxage = trim($_POST['maxage']); } else { $maxage = "120"; //default } //POST city if set if (isset($_POST['city']) && trim($_POST['city']) != '') { $city = trim($_POST['city']); } else { $city = ''; } ?> <form action="" method="POST"> Age from <input type="text" name="minage" value="<?php echo $minage;?>" size="3"> to <input type="text" name="maxage" value="<?php echo $maxage;?>" size="3"><br /> City <input type="text" name="city" value="<?php echo $city;?>"> <input type="submit" name="submit" value="Find User"> </form> <?php if (isset($_POST['submit'])) { //mysql connection $link = mysqli_connect("localhost", "database_user", "database_password", "database_name");//edit to your information //check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } //build query $query = "SELECT username FROM users WHERE (age BETWEEN $minage AND $maxage)"; if ($city != '') { $query .= " AND city='" . mysqli_real_escape_string($link, $city) . "'"; } //see query //echo $query; //fetch results if ($result = mysqli_query($link, $query)) { //check if is no results if (mysqli_num_rows($result) <= 0) { echo "No Results"; } else { //fetch associative array while ($row = mysqli_fetch_assoc($result)) { echo $row["username"] . "<br />"; } } //free result set mysqli_free_result($result); } //close connection mysqli_close($link); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/294264-can-anyone-help-me-create-search-script/#findComment-1504343 Share on other sites More sharing options...
sopranolv Posted January 30, 2015 Author Share Posted January 30, 2015 thx work's! Quote Link to comment https://forums.phpfreaks.com/topic/294264-can-anyone-help-me-create-search-script/#findComment-1504373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.