Take values from only one row of a table

Asked

Viewed 2,415 times

0

Hello, I have a project, and I would like that, when the user entered your account, could, through a PHP action, see your basic data, taking only values from that table, here’s what I have so far:

$selec = "SELECT * FROM usuarios";
$selec_query = mysql_query($selec) or die(mysql_error());

    $row = mysql_fetch_array($selec_query);
        $nome = $row['nomealuno'];
        $cidade = $row['cidadealuno'];
        $uf = $row['ufaluno'];
        $nome = $row['nomealuno'];
        $datanasc = $row['datanascaluno'];

        echo "Login: ";
        echo $row['login'];
        echo "<br> Nome: ";
        echo "$nome";
        echo "<br> Cidade: ";
        echo "$cidade";
        echo "<br> UF: ";
        echo "$uf";
        echo "<br> Data de nascimento: ";
        echo "$datanasc";

The problem is that appears only the first registered login, and all fields of the tables are with their names, I did not find any problem like mine here, let alone a clear problem in the code.

  • 2

    There’s no missing one where in your select?

  • @jbueno I’ve tried with where, could you give me an example?

  • 2

    Yes. Before you tell me something, you have the user ID that is logged in saved somewhere, right?

  • @jbueno I don’t have, I just have the login cookie, I don’t know how to get the user id automatically, could you show me?

1 answer

3


That one query

$selec = "SELECT * FROM usuarios";

You are selecting all records from the table usuarios.

Here

$row = mysql_fetch_array($selec_query);

$row receives a result line (the first in this case).

What you need to do is limit your select to bring only the registration of the user you wish to present the information. For this you will need to add a clause where in query.

$selec = "SELECT * FROM usuarios WHERE id = $idUsuario";
  • It worked the way it was, just needed a simple concatenation, hehe.

Browser other questions tagged

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