Jump to content

L


mrherman

Recommended Posts

Greetings,

 

I have a simple MySQL query which give me only one result, an integer.

 

Is there a simpler way to extract the value of "nMaxunit" rather than having to do a "while" loop and a "foreach" loop?

 

A second question is that "{$c_keytable}" seems to work the same as $c_keytable (without the brackets).  Which is preferable?

 

Thanks!

 

$sql = "SELECT MAX( riounit ) AS nMaxunit
          FROM {$c_keytable}" ;
$result = mysql_query ( $sql ) or die ("no result") ;

while ( $row = mysql_fetch_array ( $result ) )
{
   foreach ( $row as $key => $value )
      {
         $max_riounit = $value ;
      }
}

Link to comment
https://forums.phpfreaks.com/topic/206840-l/
Share on other sites

It's been a long time since I've used mysql_result() myself; I use mysql_fetch_assoc() for nearly everything. I didn't test this, but I think it's a correct example :)

 

$query = "SELECT MAX(`id`) FROM table";
$result = mysql_query($query);
$value = mysql_result($result);

Link to comment
https://forums.phpfreaks.com/topic/206840-l/#findComment-1081729
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.