Jump to content


Photo

trouble with max() in sql


  • Please log in to reply
2 replies to this topic

#1 tecdesign

tecdesign
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 25 April 2006 - 05:02 AM

while ($i < $l){
$query = mysql_query("SELECT max( topicid ) as topicmax
FROM topics");

$max_check = mysql_num_rows($query);

if($max_check > 0){ 
    while($row = mysql_fetch_array($query)){ 
    foreach( $row AS $key => $val ){ 
        $$key = stripslashes( $val ); 
}
session_register('topicmax');
$_SESSION['topicmax'] = $max;
 }
}


$maxit = $max - $i;

Ok what I am having trouble with is I want to take max (topicid) from the sql statement and pretty much make $max = max(topicid). Does anyone know how to do this?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 April 2006 - 05:20 AM


$query = mysql_query("SELECT max( topicid ) FROM topics");
$max = mysql_result ($query, 0);

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 tecdesign

tecdesign
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 25 April 2006 - 05:23 AM

Thanks Barand. I am trying to create my own forum.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users