Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]łączenie tablic
northwest
post
Post #1





Grupa: Zarejestrowani
Postów: 788
Pomógł: 1
Dołączył: 17.09.2004

Ostrzeżenie: (10%)
X----


Witam serdecznie,
Mam taki kod:
  1. function stmt_bind_assoc (&$stmt, &$out) {
  2. $data = mysqli_stmt_result_metadata($stmt);
  3. $fields = array();
  4. $out = array();
  5.  
  6. $fields[0] = $stmt;
  7. $count = 1;
  8.  
  9. while($field = mysqli_fetch_field($data)) {
  10. $fields[$count] = &$out[$field->name];
  11. $count++;
  12. }
  13. call_user_func_array(mysqli_stmt_bind_result, $fields);
  14. }
  15.  
  16. $cos2 = array();
  17.  
  18.  
  19. $mysqli = new mysqli("localhost", "root", "", "nlove");
  20. if (mysqli_connect_errno()) {
  21. printf("Connect failed: %s\n", mysqli_connect_error());
  22. exit();
  23. }
  24. $cos = array();
  25. if ($stmt = $mysqli->prepare($string)) {
  26. $stmt->execute();
  27. //$stmt->bind_result($id, $login);
  28.  
  29. stmt_bind_assoc($stmt, $cos2);
  30.  
  31. while ($stmt->fetch()) {
  32. array_merge_recursive($cos2, $cos) ;
  33. print_r($cos2);
  34. }
  35.  
  36. return $cos2;
  37. $stmt->close();
  38. }
  39. $mysqli->close()


Gdy próbuję wyświetlić nową, połączoną tablicę :
  1. foreach ($cos2 as $element)
  2. {
  3. echo $element.', <br/>';
  4. }


to dostaję tylko ostatni element tej poprzedniej... Co robię nie tak?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 19:10