Witam.
Zrobiłem automatyczne wyszukiwanie z bazy danych za pomocą towarów i fajnie pokazuje to w jednym wierszu natomiast chciałbym rozbić to na kilka kolumn (może być tabela).
Obecnie pokazuje tak:
"Nazwa towaru, ilosc, kod_artykułu, jednostka_miary".
a chciałbym żeby każdą wartośc pokazywał w osobnej komórce tabeli.
Poniżej kod:
  1. <script type="text/javascript">
  2. function lookup(inputString) {
  3. if(inputString.length == 0) {
  4. // Hide the suggestion box.
  5. $('#suggestions').hide();
  6. } else {
  7. $.post("rpc1.php", {queryString: ""+inputString+""}, function(data){
  8. if(data.length >0) {
  9. $('#suggestions').show();
  10. $('#autoSuggestionsList').html(data);
  11. }
  12. });
  13. }
  14. } // lookup
  15.  
  16. function fill(thisValue) {
  17. $('#inputString').val(thisValue);
  18. setTimeout("$('#suggestions').hide();", 200);
  19. }
  20. </head>
  21. <body>
  22. <div>
  23. <form method="POST" action="f2.php">
  24. <div>
  25. Wybierz towar:
  26. <br />
  27. <tr>
  28. <td><input type="text" name="b1" size="150" value="" autocomplete="off" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" /></td>
  29.  
  30. </tr>
  31.  
  32. </div>
  33. <div class="suggestionsBox" id="suggestions" style="display: none;">
  34. <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
  35. <div class="suggestionList" id="autoSuggestionsList">
  36. &nbsp;
  37. </div>
  38. </div>
  39.  
  40. </body>
  41. </html>
  42.  


oraz plik php, który odpowiada za resztę:
  1. <?php
  2.  
  3.  
  4. if(!$db) {
  5. // Show error if we cannot connect.
  6. echo 'ERROR: Could not connect to the database.';
  7. } else {
  8. // Is there a posted query string?
  9. if(isset($_POST['queryString'])) {
  10. $queryString = iconv('UTF-8','latin2',$queryString);
  11. $queryString = $db->real_escape_string($_POST['queryString']);
  12.  
  13.  
  14.  
  15.  
  16. // Is the string length greater than 0?
  17.  
  18. if(strlen($queryString) >0) {
  19. // Run the query: We use LIKE '$queryString%'
  20. // The percentage sign is a wild-card, in my example of countries it works like this...
  21. // $queryString = 'Uni';
  22. // Returned data = 'United States, United Kindom';
  23.  
  24. // YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
  25. // eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
  26.  
  27. $db->query("SET NAMES latin2");
  28.  
  29.  
  30. $query = $db->query("SELECT nazw_art, ilosc, kod_art, jedn_miary FROM artykul WHERE nazw_art LIKE '$queryString%'");
  31.  
  32. if($query) {
  33. // While there are results loop through them - fetching an Object (i like PHP5 btw!).
  34. while ($result = $query ->fetch_object()) {
  35. // Format the results, im using <li> for the list, you can change it.
  36. // The onClick function fills the textbox with the result.
  37.  
  38.  
  39. // YOU MUST CHANGE: $result->value to $result->your_colum
  40.  
  41. // echo '<li onClick="fill(\''.$result->nazw_art.', '.$result->ilosc.', '.$result->kod_art.', '.$result->jedn_miary.'\');">'.$result->nazw_art.', '.$result->ilosc.','.$result->kod_art.', '.$result->jedn_miary.'</li>';
  42.  
  43. echo '<tr onClick="fill(\''.$result->nazw_art.', '.$result->ilosc.', '.$result->kod_art.', '.$result->jedn_miary.'\');">'.$result->nazw_art.', '.$result->ilosc.','.$result->kod_art.', '.$result->jedn_miary.'</tr>';
  44.  
  45. }
  46. } else {
  47. echo 'ERROR: There was a problem with the query.';
  48. }
  49. }
  50. else
  51.  
  52. {
  53. // Dont do anything.
  54. }
  55. // There is a queryString.
  56. }
  57.  
  58. else
  59.  
  60. {
  61. echo 'There should be no direct access to this script!';
  62. }
  63. }
  64. ?>

czy ktoś może pomóc ?