Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
autocompletar no muestra todos los datos

Apliqué la función de autocompletar al cuadro de búsqueda, pero cuando ingreso algún valor en el cuadro de búsqueda, siempre me da el mismo resultado.
Me di cuenta de que no recorrí la base de datos, por eso sigo obteniendo el mismo resultado.
Cambié mi consulta para poder obtener lo que quiero, pero el resultado sigue siendo el mismo.
aquí está mi ajax para autocompletar, y no estoy seguro de si es la forma correcta de hacerlo. Pero la función de búsqueda funciona, excepto que no muestra todos los datos.

 function autoComplete(){ $('#keywords').autocomplete({ source: 'autoComplete.php', minLength : 3, select: function(event, ui) { console.log(ui); $('#chosenEvent').append(ui.item.value + "\n"); } });

Aquí está el código php

 <?php // include the file for the database connection include_once("database_conn_getOffers.php"); function autoC($conn){ $sql = "select eventTitle from te_events_special_offers eventTitle ORDER BY eventTitle"; $rsOffer = mysqli_query($conn, $sql); //$offer = mysqli_fetch_all($rsOffer, MYSQLI_ASSOC); $titles = array(); while($title = mysqli_fetch_assoc($rsOffer)){ $titles[] = $title; } foreach ($titles as $title) return json_encode($title); } echo autoC($conn) ?>

Aquí está el enlace al que me refiero haga clic aquí

¡Gracias por tu ayuda!
Así que ahora, cambié el método ajax con el siguiente código y funciona, pero todavía no tengo idea de qué está mal con mi código ajax anterior. También modifiqué el código php eliminando el foreach y agregué el método de implode

 $.ajax({ method :"get", url :"autoComplete.php" }) .done(function(data, status, jqxhr){ var eventList; console.log(data); eventList = data.split(','); $("#keywords").autocomplete({ minLength :2 , source : eventList, select: function(event,ui){ console.log(ui); } //end autocompoete }); });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Intente primero tener resultados para codificar, luego los usaremos. Ejecute este código junto con ningún otro al mismo tiempo y díganos qué obtiene (supuse que tiene columnas ID + TÍTULO, si no, corrija el código antes de usarlo). Además, su consulta original parece rara -> $sql = "SELECCIONE eventTitle FROM te_events_special_offers eventTitle ORDER BY eventTitle"; /* marcar la parte en negrita */

Además : realmente debería pensar en declaraciones preparadas y errores_reporting

 <?php error_reporting(E_ALL); ini_set('display_errors', 1); include"config.inc.php"; $mysqli = mysqli_connect("$host", "$user", "$mdp", "$db"); if (mysqli_connect_errno()) { echo "Error connecting : " . mysqli_connect_error($mysqli); } $query = " SELECT idTitle, eventTitle FROM te_events_special_offers ORDER BY eventTitle "; /* check names used here and adapt to yours */ $stmt = $mysqli->prepare($query); $results = $stmt->execute(); $stmt->bind_result($idTitle, $eventTitle); $stmt->store_result(); if ($stmt->num_rows > 0) { $events = array(); $event = array(); while($stmt->fetch()){ echo"[ $idTitle -> $eventTitle ]<br />"; $event["id"] = "$idTitle"; $event["title"] = "$eventTitle"; array_push($events, $event); } } else { echo"[ no data ]"; } print_r($events); echo json_encode($events); ?>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!