0
<?
$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

Edited by pyTony: fixed formatting

Attachments max.JPG 9.84 KB
3
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by twiss
0

- 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.

0
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

Attachments mx2.JPG 17 KB
0

Just use mysql query for the same

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

This will suffice your requirement.

0

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 ?> .

0

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

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

This will suffice your requirement.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.