0
$gateway = new EpisodeGateway();
$db = $gateway ->acces_db();
$Ermittler = array();
$Ermittler = $gateway ->get_hauptkommissar($db);

$index = 0;
$counteur = 0;

for($x=0;$x < sizeof($Ermittler);$x++)
{
    echo "<strong>".$Ermittler[$x][0]."</strong>";
    echo "<br>";
    $result = $gateway->get_episode_by_police($db,$Ermittler[$x][0]);
}
public function get_episode_by_police($db,$Ermittler)
{
    $mysqli = new mysqli($db);
    $request = 'select titel,Ertaussstrahlung,stadt from folge where Ermittler=$Ermittler[0]';
    $result = mysqli_query($db,'select titel,Ertaussstrahlung,stadt from folge where Ermittler= %s',$Ermittler[0]);
    
    $result = mysqli_fetch_assoc($result);
    
    return $result;
}

I do not know why, it is not working. I don't have any result in the variable result in the for loop. Don't be mean with me please. I'm still a beginner

El_Vanja
  • 3,660
  • 4
  • 18
  • 21
Math142
  • 19
  • 6
  • 1
    How do you determine that there is no result? What do you get in that variable? Are there any errors in PHP's log? – El_Vanja May 14 '21 at 22:55
  • When I echo the result, nothing appears – Math142 May 14 '21 at 22:57
  • You never use the `$request` variable, what is it for? – Barmar May 14 '21 at 22:58
  • You already used the subscript `[0]` when calling the function. You probably don't need to do it again inside the function. – Barmar May 14 '21 at 23:00
  • I forgot to erase it. I tried something before and I let it there. – Math142 May 14 '21 at 23:00
  • I recommend you learn how to use `foreach` to loop over arrays. – Barmar May 14 '21 at 23:01
  • You're also not using `$mysqli`. – Barmar May 14 '21 at 23:02
  • 1
    `where Ermittler= %s',$Ermittler[0]` is not how you use `mysqli_query`. I would suggest looking into [prepared statements](https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement). – El_Vanja May 14 '21 at 23:02
  • Ok Thank you. I check that out and I will see if it is working. Thank you! – Math142 May 14 '21 at 23:05
  • You would benefit from adopting the approach to let `mysqli` throw errors (that way you'd immediately be aware of them). Here's a thorough [guide](https://stackoverflow.com/a/22662582/4205384) on that. – El_Vanja May 14 '21 at 23:05
  • Thanks a lot for your comments and tips I will try everything tomorrow – Math142 May 15 '21 at 00:08

0 Answers0