0

I'm not familiar with MySQLi

<?php
    $bestaat = mysql_query("SELECT * FROM badgesdownload LIMIT 7");  
    while($bestaat2 = mysql_fetch_array($bestaat)) {
        $bestaat3 = $bestaat2['naam'];
        $txt = mysql_query("SELECT * FROM badgesdownload WHERE naam = '".$bestaat3."'"); 
        while($txt2 = mysql_fetch_array($txt)){
            $txt3 = $txt2['txt'];   
            echo $bestaat3; 
            echo'<br>';
            echo $txt3;
            echo'<br>';
        }
    }
?>

How can I change this script to mysqli?

TotPeRo
  • 6,561
  • 4
  • 47
  • 60

1 Answers1

0

Mysqli - procedural method is fairly similar. Just add your database connection as the first parameter to a query, and an 'i' in all the functions...

$bestaat = mysqli_query($db, "SELECT * FROM badgesdownload LIMIT 7");

while($bestaat2 = mysqli_fetch_array($bestaat)) {
    $bestaat3 = $bestaat2['naam'];
    $txt = mysqli_query($db, "SELECT * FROM badgesdownload WHERE naam = '$bestaat3'");
    while($txt2 = mysqli_fetch_array($txt)){              
        echo $bestaat3.'<br>'.$txt2['txt'].'<br>';
    }
}

I have also fixed some obvious errors.. ..missing close braces was the main one.

MaggsWeb
  • 3,018
  • 1
  • 13
  • 23