wie

2016-07-25 16 views
3

in einem Etikett mit der automatischen Vervollständigung in PHP eine der beiden Datenbankwerte anzuzeigen Dies ist mein Code ein:wie

<?php include("config.php"); 
include("session-user.php"); 

$term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends 

$qstring = "SELECT product_title, product_details, product_id FROM tbl_product WHERE product_title LIKE '".$term."%' OR product_details LIKE '".$term."' and is_delete = '0'"; 
$result = mysqli_query($con,$qstring);//query the database for entries containing the term 

while ($row = mysqli_fetch_array($result))//loop through the retrieved values 
{ 
    $row['label']=htmlentities($row['product_title']); 
    $row['label']=htmlentities($row['product_details']); 
    $row['product_id']=htmlentities($row['product_id']); 
    $row_set[] = $row;//build an array 
} 
echo json_encode($row_set); 

zur Zeit nur eines der labels zeigt, möchte ich mit einem der beiden suchen Etiketten

Wie ich es erreichen kann?

+0

aufgrund gleichen Indizes zunächst ein überschreiben, wie '$ row [ 'label'] = htmlentities ($ row [ 'Produktname']); $ row [ 'label1'] = htmlentities ($ row [ 'Produkt_Details']); 'überprüfen i –

+0

Sekunden einen Index zu' label1' geändert haben nun ihr nicht die label1 Wert – Learner

Antwort

2

Problem ist in diesem Code: -

$row['label']=htmlentities($row['product_title']); 
$row['label']=htmlentities($row['product_details']); 

aufgrund gleichen Indizes (label) zunächst eine überschreiben, verwenden wie: -

$row['label']=htmlentities($row['product_title']); 
$row['label1']=htmlentities($row['product_details']); 

Check i Sekunde geändert haben einen Index zu label1

Autocomplete arbeiten mit einem Etikett pro Wert, so dass Sie sie verketten (Label-Label1) und zeigen können.

Oder

kann dies hilft Ihnen: -

while ($row = mysqli_fetch_array($result))//loop through the retrieved values 
{ 
    if($row['product_title'] !=='' && $row['product_details'] ==''){ // if product_title is present but product_details is not present 
     $row['label']=htmlentities($row['product_title']); 
     $row['product_id']=htmlentities($row['product_id']); 
     $row_set[] = $row;//build an array 
    }else if($row['product_details'] !=='' && $row['product_title'] ==''){ // if product_details is present but product_title is not present 
     $row['label']=htmlentities($row['product_details']); 
     $row['product_id']=htmlentities($row['product_id']); 
     $row_set[] = $row;//build an array 
    }else if($row['product_details'] !=='' && $row['product_title'] !==''){ // if both are present 
     $row['label']=htmlentities($row['product_title']); 
     $row['product_id']=htmlentities($row['product_id']); 
     $row_set[] = $row;//build an array 
    } 
} 

Hinweis: - in diesem obigen Code, wenn beide Werte (product_title und product_title) vorhanden sind, dann wird product_title zeigen, wie ein Label, sonst ein entsprechender Wert, wird als Label angezeigt.

+1

Dank zeigt für die Markierung. froh, Ihnen zu helfen :) Prost –

1

Versuchen Sie, diese

$row['label1']=htmlentities($row['product_title']); 
    $row['label2']=htmlentities($row['product_details']); 

und Änderungsanfrage an

$qstring = "SELECT product_title, product_details, product_id FROM tbl_product WHERE product_title LIKE '".$term."%' OR product_details LIKE '".$term."%' and is_delete = '0'"; 
+0

seine Anzeige leer in der Bezeichnung – Learner