<?
$koneksi = mysql_connect("localhost",'root','');
if(!koneksi){
        die ('tidak ada koneksi'.mysql_error());
    }

    ?><table width="294" border="1">

  <tr>
      <td width="20" bgcolor="#CCCCCC"><pre>id</pre></td>
      <td width="56" bgcolor="#CCCCCC"><pre>Pembeli</pre></td>
      <td width="60" bgcolor="#CCCCCC">Nilai 1</td>
      <td width="62" bgcolor="#CCCCCC">Nilai 2</td>
      <td width="62" bgcolor="#CCCCCC"><pre>Total</pre></td>
  </tr>
  <?
mysql_select_db('dbpenjualan', $koneksi);
$query = "select * from tpembeli";
$hasil = mysql_query($query);

while($row = mysql_fetch_array($hasil)){
?>
  <tr>
    <td><? echo $row['id_pembeli']; ?>&nbsp;</td>
    <td><? echo $row['nama_pembeli']; ?>&nbsp;</td>
    <td><? echo $nilai_1 = $row['nilai1']; ?></td>
    <td><? echo $nilai_2 = $row['nilai2']; ?></td>
    <td><? echo $total = $nilai_1 + $nilai_2; ?></td>
  </tr>
  <? } ?>
</table>
<p>View Total max = ? </p>

thank's

- Could you put your code in code tags?
- You forgot a $ on line 3.
- There's a MAX function in MySQL.
- You could also do something like this: if($max < $total) $max = $total; . Or change $total to the var you want the highest of.

id
Pembeli


Nilai 1
Nilai 2
Total

<?

$koneksi = mysql_connect("localhost",'root','');
if(!$koneksi){
die ('tidak ada koneksi'.mysql_error());
}
mysql_select_db('dbpenjualan', $koneksi);
$query = "select * from tpembeli";
$hasil = mysql_query($query);

while($row = mysql_fetch_array($hasil)){
?>
<? echo $row['id_pembeli']; ?>
<? echo $row['nama_pembeli']; ?>
<? echo $nilai_1 = $row['nilai1']; ?>
<? echo $nilai_2 = $row['nilai2']; ?>
<? echo $total = $nilai_1 + $nilai_2; ?>

<? } ?>
View Total max = <? if($max < $total) $max = $total; echo $max; ?>

should be 170 instead of 66

Just use mysql query for the same

$query=mysql_query("SELECT max(".$total.") from tpembeli";

This will suffice your requirement.

You put it on the wrong place. It should be before <? } ?> , of course, and than on the place you want to have it you can do <?= $total ?> .

Ohh i missed ')'....use this one-

$query=mysql_query("SELECT max(".$total.") from tpembeli");

This will suffice your requirement.

Thank's All

You need to expand it, so that if $max is set, $name is set too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.