Page 1 sur 1

Problème avec mon MAX ?!

Posté : 17 sept. 2005, 12:44
par tioumen
Salut à tous !!!

Voila j'ai un problème pour afficher mon résultat après cette requête :
function maximum()
{
$i=0;
	include("connect.php");
	$table=mysql_query("select max(id) from news");
	
		while ($ligne = mysql_fetch_array($table))
		{
			$i++;
			$res=$ligne["id"];
			echo "$res";
		}
}
Voila l'erreur :

Code : Tout sélectionner

Notice: Undefined index: id in g:...\fonction.php on line 67
Merci pour votre aide ....

Posté : 17 sept. 2005, 13:06
par Truc
Salut, tu essay de récuperer une valeur que tu n'a pas séléctionné directement a préalable, essai comme ceci:

function maximum()
{
$i=0;
    include("connect.php");
    $table=mysql_query("select max(id) as maxi from news");
    
        while ($ligne = mysql_fetch_array($table))
        {
            $i++;
            $res=$ligne["maxi"];
            echo "$res";
        }
}

Posté : 17 sept. 2005, 13:18
par Cyrano
Tu pourrais simplifier:
<?
function maximum()
{
    include("connect.php");
    $table = mysql_query("select max(id) from news");

    $res = mysql_result($table, 0);
    echo("<p>". $res ."</p>\n");
}
?>

Posté : 17 sept. 2005, 14:04
par tioumen
Merci beaucoup !!

Grosse erreur de ma part il est vrai !!!! :oops: