MySQL petite questoin

Résolu
Bonjour,
je veux recuperer le dernier id de la table Mysql j'ai utiliser cette requet mais elle affiche "S"

<?php
//connexion a la BDD
mysql_connect("localhost", "root", "xxx");
mysql_select_db("xxx");

$query = "SELECT * FROM 'user_wait' WHERE id = MAX(id)";
echo $query['id'];

?>

Merci
Configuration: Windows Vista
Firefox 3.0.5
PHP 5.2.8
MySQL 5.1.30

4 réponses

  1. Contributeur
    Salut,

    premierement tu mets ton champs id en clé primaire

    et ensuite tu fais un order by id desc limit 1

    donc:

    <?php
    //connexion a la BDD
    mysql_connect("localhost", "root", "xxx");
    mysql_select_db("xxx");
    
    $query = "SELECT * FROM 'user_wait' ORDER BY id desc limit 1";
    echo $query['id'];
    
    ?> 
    
    0
    1. Merci pour ta réponse mais elle affiche un S
      je trouve pas ou es le problème
      0
      1. Contributeur
        ton champs id est auto increment ?
        ton champs id est en clée primaire ?
        0
    2. Ben je sais pas trop si c'est bon, mais essaye de fioné kom ca ...

      <?php
      //connexion a la BDD
      mysql_connect("localhost", "root", "xxx");
      mysql_select_db("xxx");
      
      $query = "SELECT * FROM 'user_wait' order by id desc";
      echo $query['id'];
      
      ?> 
      


      Ca peut peut etre marché ;)

      0
      1. Pourquoi tu mets ta table entre guillemets ?

        Ensuite récupère la valeur de ta requête :

        <?php
        //connexion a la BDD
        mysql_connect("localhost", "root", "xxx");
        mysql_select_db("xxx");

        $query = ("SELECT * FROM user_wait order by id desc") or die (mysql_error())
        $resultat = mysql_fetch_assoc($query);
        echo $resultat['id'];
        ?>
        0