Doubt Mysql + PHP

Asked

Viewed 39 times

0

Hello, I am developing a management system of camepeonatos online (Fifa, pes) and I have a problem, now I am doing the part where the user will post the result of the game, informing the score and the players who made the goals, for this I need to access the database and select the list of players of the user’s club and put them on a button in the form of select so click pro user, I’m beginner would like to know how I do this, with which function, follow example of my code where I was able to get the BD data

<?php
$link = mysqli_connect("localhost", "root", "usbw", "mith");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$query = "
SELECT C.nome_clube , J.nome_jogador
  FROM clube as C 
 RIGHT OUTER JOIN conta_user as UC ON C.id_clube = UC.id_conta
 RIGHT OUTER JOIN jogador as J ON C.id_clube = J.id_jogador";

if ($result = mysqli_query($link, $query)) {

    /* fetch associative array */
    while ($row = mysqli_fetch_assoc($result)) {
        printf ("%s (%s)\n", $row["nome_clube"], $row["nome_jogador"]);
    }

    /* free result set */
    mysqli_free_result($result);
}

/* close connection */
mysqli_close($link);
?>

1 answer

0


If I understood correctly you want to make a select field in html with the values of the database, if that would be so, where the value of the options would be the id for you to recover by post or javascript and manipulate as you want:

<select name="JOGADOR" id="JOGADOR" >
      <?php do { ?>
        <option value="<?php echo $row['id_jogador']; ?>">
          <?php echo $row['nome_jogador'];?>
        </option>
      <?php  } while ($row = mysqli_fetch_assoc($result)); ?>
</select>
  • Thank you, sorry if I was not clear on the question I am beginner still my first project, but thank you was that same ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.