Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] Problem mit bind_param() in Kombination mit foreach()

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Erledigt] Problem mit bind_param() in Kombination mit foreach()

    Hallo

    Warum bekomme ich hier (siehe code unten -> foreach) ein Array mit nur einen Wert zurück, anstatt ein Array mit mehreren?

    PHP-Code:
    $db = new mysqli(DBHOSTDBUSERDBPWDBNAME);
            
            
    $sql7 'SELECT seats FROM roomsAndTables WHERE tableId = ?';
            
    $result3 $db->prepare($sql7);
            
    $result3->bind_param('i'$oneTableSeats);
            
            foreach (
    $_POST['table'] as $oneTableSeatsId)
            {
                
    $oneTableSeats intval($oneTableSeatsId);
                
    $result3->execute();
            }
            
            
    $result3->bind_result($resSeats);
            
            while (
    $result3->fetch())
            {
                
    $_oneTable['seats'][] = $resSeats;
            }
            
    $db->close();

    // [...]

    // test:
    echo '<br><br>'var_dump($_oneTable['seats']); 
    An anderer Stelle in meinem Code habe ich einen Insert-Befehl und da funktioniert bind_param() in Kombination mit foreach().

    Habe schon gestern und heute gegoogelt - bin auch auf die Funktion call_user_func_array() gestoßen jedoch bekomme ich bei Aufruf dieser Funktion die Fehlermeldung, dass bind_param keine gültige Funktion ist.

    Ich bitte euch daher um Hilfe.


    Danke im Voraus und
    mfG APH

    komisch: Kaum macht man`s richtig funktioniert`s a scho.

  • #2
    PHP-Code:
            $result3->bind_param('i'$oneTableSeats); 
             
            foreach (
    $_POST['table'] as $oneTableSeatsId
            { 
                
    $oneTableSeats intval($oneTableSeatsId); 
    Beim bind_param() gibt es die Variable noch nicht. Oder ich verguck mich grad
    [COLOR=#A9A9A9]Relax, you're doing fine.[/COLOR]
    [URL="http://php.net/"]RTFM[/URL] | [URL="http://php-de.github.io/"]php.de Wissenssammlung[/URL] | [URL="http://use-the-index-luke.com/de"]Datenbankindizes[/URL] | [URL="https://www.php.de/forum/webentwicklung/datenbanken/111631-bild-aus-datenbank-auslesen?p=1209079#post1209079"]Dateien in der DB?[/URL]

    Kommentar


    • #3
      Zitat von VPh Beitrag anzeigen
      Beim bind_param() gibt es die Variable noch nicht. Oder ich verguck mich grad
      Wie gesagt: An anderer Stelle (siehe Code unten) funktioniert es ohne Probleme. Wieso also nicht an der Stelle, wie in Post#1 geschrieben? Wo liegt der Fehler bzw. was muss ich ändern, damit ich das gewünschte Array bekomme?

      PHP-Code:
      // [...]

      $sql6 'INSERT INTO res (resDetailId, tableId) VALUES (?, ?)';
      $entry2 $db->prepare($sql6);
      $entry2->bind_param('ii'$lastId$oneTableId);
              
      foreach (
      $_POST['table'] as $oneTable)
      {
          
      $oneTableId $oneTable;
          
      $lastId $tmpId;
          
      $entry2->execute();
      }

      // [...] 
      mfG APH

      komisch: Kaum macht man`s richtig funktioniert`s a scho.

      Kommentar


      • #4
        Kurz geprüft, du überschreibst dein Ergebnis bei jedem Durchgang, und bekommst deshalb nur das letzte Ergebnis in dein Array.

        PHP-Code:
                foreach ($ids as $oneTableSeatsId
                { 
                    
        $oneTableSeats intval($oneTableSeatsId); 
                    
        $result3->execute(); 
                    
        $result3->bind_result($resSeats); 
                    if (
        $result3->fetch()) 
                    { 
                        
        $_oneTable['seats'][] = $resSeats
                    }
                } 
        [COLOR=#A9A9A9]Relax, you're doing fine.[/COLOR]
        [URL="http://php.net/"]RTFM[/URL] | [URL="http://php-de.github.io/"]php.de Wissenssammlung[/URL] | [URL="http://use-the-index-luke.com/de"]Datenbankindizes[/URL] | [URL="https://www.php.de/forum/webentwicklung/datenbanken/111631-bild-aus-datenbank-auslesen?p=1209079#post1209079"]Dateien in der DB?[/URL]

        Kommentar


        • #5
          Danke für deine Hilfe VPh!
          Jetzt funkt es!

          komisch: Kaum macht man`s richtig funktioniert`s a scho.

          Kommentar

          Lädt...
          X