Sunday 15 April 2012

php - dynamic dropdown displays nothing -



php - dynamic dropdown displays nothing -

i trying enable user select movies title or actors (e.g in case forgot film name remembered actor/actress in movie, able find film typing actor name). used jquery auto-comlete film names or actor names.

below have tried. auto-complete parts works fine (i.e, when user take moviebytitle , start writing title, autocomplete suggestion works, actor names.

problem:

when user write actor name, autocomplete works fine, dynamic dropdown menu appeared, problem dropdown displays nothing :| kindly help me find problem code? thanks,

<select id="selecttype" name="source"> <option value="">moviesby</option> <option value="bytitle">bytitle</option> <option value="byactor">byactor</option> </select> <input type="textbox" name= "tag" id="tags"> <select id="movieimdbid" name="movieimdbid[]" multiple="multiple" width="200px" size="10px" style="display: none;"> </select> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script> <script type="text/javascript"> $(document).ready(function () { //create widget default info source $("#tags").autocomplete({ source: "actorsauto.php", minlength: 2 }); $("#selecttype").change(function () { // assign new info source : if ($(this).val() == "bytitle") $("#tags").autocomplete("option", "source", "filmsauto.php"); else if ($(this).val() == "byactor"){ $("#tags").autocomplete({ source: "actorsauto.php", minlength: 2, select: function (event, ui){ var selectedval = $(this).val(); //this selected value autocom plete // here goes ajax call. $('#movieimdbid').show(); $.post("actions.php", {q: selectedval, q2: $("#selecttype").val()}, function (response){ // response variable above contain alternative tags. set in dropdown. $("#movieimdbid").html(response); }); } }); } }); }); </script>

and here actions.php:

<?php if(isset($_get['q']) && !empty($_get['q']) && isset($_get['q2']) && !empty($_get['q2']) ){ $q = $_get['q']; $q2 = $_get['q2']; include('imdbconnection.php'); $sql = $conn->prepare("select distinct movieimdbid movie_rolenames castname = :q"); $sql->execute(array(':q' => $q)); // initialize variable send ajax call, still waiting script completed. $html = ""; $results = $sql->fetchall(pdo::fetch_obj); while($results $row){ $option = '<option value="' . $row['movieimdbid'] . '">' . $row['movieimdbid'] . '</option>'; $html .= $option; } echo $html; exit; } ?> update:

this see:

you mixing mysql , pdo seek utilize pdo instead of mysql. need add together value in $html variable instead of overwrite value 1 time again , again. alter lower part of code because

$results = $sql->fetchall(pdo::fetch_obj); while($results $row){ $option = '<option value="' . $row->movieimdbid . '">' . $row->movieimdbid . '</option>'; $html.= $option; } echo $html; exit;

php jquery ajax drop-down-menu autocomplete

No comments:

Post a Comment