Php msql aléatoire

francois59510 Messages postés 20 Statut Membre -  
francois59510 Messages postés 20 Statut Membre -
Bonjour, je viens de commencé le php, mais j'ai un problème je veux faire un qcm sur du voc mais il faut que dans mon tableau il y est qu'une donnée sur deux soit la traduction anglais soit Français et j' arrive pas!HELP ME!
voici mon script :
<div id="corp">
<?php include('connexion.inc'); ?>
<?php
$reponse= $bdd->query('SELECT * FROM voc_anglais_oliver');
?>
<table>
<tr>
<td><strong>Anglais:</strong></td>
<td><strong>Français:</strong></td>
</tr>
</table>
<?php

while ($donnees = $reponse->fetch())
{
?>

<table>
<tr>
<td> <?php echo $donnees['anglais']; ?></td>
<td><?php echo $donnees['francais']; ?></td>
</tr>
</table>

<?php
}
$reponse->closeCursor();

?>

</div>
Merci!

1 réponse

  1. Reivax962 Messages postés 3742 Statut Membre 1 011
     
    Bonjour,

    Tu peux utiliser une fonction aléatoire :
    <div id="corp">
    <?php include('connexion.inc'); ?>
    <?php
        $reponse= $bdd->query('SELECT * FROM voc_anglais_oliver');
    ?>
        <table>
            <tr>
                <td><strong>Anglais:</strong></td>
                <td><strong>Français:</strong></td>
            </tr>
        </table>
    <?php
    
    while ($donnees = $reponse->fetch())
    {
        $anglais = (mt_rand(0, 1) == 0);
    ?>
    
        <table>
            <tr>
                <td><?php echo ($anglais) ? $donnees['anglais'] : ''; ?></td>
                <td><?php echo ($anglais) ? '' : $donnees['francais']; ?></td>
            </tr>
        </table>
    
    <?php
    }
    $reponse->closeCursor();
    
    ?>
    
    
    </div> 


    Xavier
    0
    1. francois59510 Messages postés 20 Statut Membre
       
      Merci!
      0