php - View customer info on select change -
i'm creating page allow admin select user drop downwards list, populates database. when person selected, info associated person viewed on page. have select statement selects info , drop downwards menu populating correctly. however, i'm unsure on how selected user's info display on page 1 time selected. need exclusively different select statement , query checks client selected? or there way?
customer.php
<div id="view_form" class="view"> <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>"> <fieldset> <label for="viewcustomer">select customer</label> <?php echo "<select name='selectcust' id='selectcust'>"; echo "<option></option>"; while($row = mysqli_fetch_assoc($custresult)){ $name = "{$row['fname']} {$row['lname']}"; echo "<option>$name</option>"; } echo "</select>"; ?> </fieldset> </form> </div> viewuser.php
if(isset($search)){ $select = "select * $cust acctnum='{$search}'"; $result = mysqli_query($db, $select); if(mysqli_num_rows($result) > 0){ if($row = mysqli_fetch_assoc($result)){ $acct = "{$row['acctnum']}"; echo $acct; } } } script.js
$(document).ready(function(){ function searchajax(){ var search = $('#selectcust').val(); $.post('includes/viewuser.php', {searchusers: search}, function(data){ $('#view_form').append(data); }) } $('#selectcust').on('change', function(ev){ ev.preventdefault(); searchajax(); }) })
search.php
<script type="text/javascript "src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type='text/javascript'> $(document).ready(function(){ $(".dropdown-users").on("change",function(event){ event.preventdefault(); search_ajax_way(); }); }); function search_ajax_way(){ var search_this=$("dropdown-users").val(); $.post("ajaxsearch.php", {searchusers : search_this}, function(data){ $(".results").html(data); }) } </script> <div id="view_form" class="view"> <form method="post"> <fieldset> <label for="viewcustomer">select customer</label> <?php echo "<select class="dropdown-users">"; echo "<option></option>"; while($row = mysqli_fetch_assoc($custresult)){ $name = "{$row['fname']} {$row['lname']}"; $acct = $row['acctnum']; echo "<option value="$acct">$name ($acct)</option>"; } echo "</select>"; ?> </fieldset> </form> </div> <label>enter</label> <input type="text" name="search_query" id="search_query" placeholder="what looking for?" size="50"/> <input type="<span id="il_ad1" class="il_ad">submit</span>" <span id="il_ad6" class="il_ad">value</span>="search" id="button_find" /> <div class="results"></div> //******************************************************************************************** ********************************************************************************************//
ajaxsearch.php
<?php $con = mysqli_connect("localhost","my_user","my_password","my_db"); // come in info here $term = $_post['searchusers'] $term = mysqli_real_escape_string($con, $term); if($term == "") echo "enter search"; else { $query = mysqli_query($con, "select * userdatebasehere id = '{$term}' "); $string = ''; if (mysqli_num_rows($query) > 0) { if (($row = mysqli_fetch_assoc($query)) !== false) { $string = "{$row['id']}"; } } else { $string = "this person not exist"; } echo $string; } ?> php jquery ajax mysqli
No comments:
Post a Comment