0

i think this problem can be solve by many of you.someone please help me in displaying number in a bil column. make it display like 1 2 3 4 5 rather than fetch it from database.here is the code :

<?php
 session_start(); //starts the session
 if($_SESSION['id']){ // checks if the user is logged in  
 }
 else{
  header("location: index.php"); // redirects if user is not logged in
}
$id = $_SESSION['id']; //assigns user value

?>
<html>
<head>
    <title>Sistem Laporan</title>
</head>

<body><div align="center">
<center><img src="pic/latestbanner.jpg" width="1000" height="150" border="3"></center>
  <table width="1004" border="1">
    <tr>
      <td width="98"><center><a href="home.php">Laman Utama</a></center></td>
      <td width="554" height="30"><center>Log masuk sebagai <?php Print "$id"?>!</center>
      <!--Displays user's name--> </td>
      <td width="162"><center><a href="tukar_password.php">Kata Laluan</a></center></td>
      <td width="164"><center><a href="logout.php">Log Keluar</a></center></td>
    </tr>
  </table></div>
  <center><table width="1000" height="346" border="1">
   <tr>
        <td>
      <center><table width="993" height="324" border="0">
        <tr>
          <td colspan="3" height="27"><a href="home.php">Laman Utama</a> > 
  <a href="pengurusan_sistem.php">Pengurusan Sistem</a> > <a href="senarai_pengguna.php">
 Senarai Pengguna</a></td>

        </tr>
        <tr>
            <td width="157">&nbsp;</td>
            <td width="585">&nbsp;</td>
            <td width="237">&nbsp;</td>
        </tr>
        <tr>
            <td align="center"><input type="button" value="Kembali"  onclick="window.location.href='pengurusan_sistem.php'"></td>
            <td>&nbsp;</td>
            <td align="center"><input type="button" value="Daftar Pengguna Baru" onclick="window.location.href='register.php'"></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr valign="top">
          <td colspan="3" height="235"><center><table border="1px" width="95%">
        <tr>
            <th width="4%">Bil</th>
            <th width="7%">ID Pengguna</th>
            <th width="6%">Kata Laluan</th>
            <th width="7%">Tahap Pengguna</th>
            <th width="25%">Nama & Emel</th>
            <th width="10%">No KP</th>
            <th width="9%">Telefon Pejabat</th>
            <th width="9%">Sektor</th>
            <th width="8%">Jawatan</th>
            <th width="8%">Kemaskini</th>
            <th width="7%">Buang</th>

        </tr>
        <?php




            mysql_connect("localhost", "root","") or die(mysql_error()); //Connect to server
            mysql_select_db("sistem_laporan") or die("Cannot connect to database"); //connect to database






            $query = mysql_query("Select * from profil"); // SQL Query

            $reset = mysql_query("ALTER TABLE profil AUTO_INCREMENT = 1"); //reset auto increment



            while($row = mysql_fetch_array($query))
            {


                Print "<tr>";
                    Print '<td align="center">'. $row['bil'] . "</td>";
                    Print '<td align="center">'. $row['id'] . "</td>";
                    Print '<td align="center">'. $row['katalaluan']. "</td>";
                    Print '<td align="center">'. $row['level'] . "</td>";
                    Print '<td align="center">'. $row['nama'] ."<br/>". $row['emel'] . "</td>";
                    Print '<td align="center">'. $row['noKp']. "</td>";
                    Print '<td align="center">'. $row['noPej']. "</td>";
                    Print '<td align="center">'. $row['sektor']. "</td>";
                    Print '<td align="center">'. $row['jawatan']. "</td>";
                    Print '<td align="center"><a href="updateUser.php?bil='. $row['bil'] .'">kemaskini</a></td>';
                    Print '<td align="center"><a href="#" onclick="delFunc('.$row['bil'].')">buang</a> </td>';

                Print "</tr>";
            }
        ?>
        <script>
        function delFunc(bil)
        {
        var r=confirm("Anda pasti ingin membuang rekod pengguna ini?");
        if (r==true)
          {
            window.location.assign("delete_pengguna.php?bil=" + bil);
          }
        }
    </script>
</table></center></td>


    </tr>
    <tr>
          <td height="46">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>

    </tr>
    </table></center>
     </td>
    </tr>


</table></center>

 <center><?php require_once('footer.php'); ?></center>   



</body>
</html>

there you can see that i'm retrieving the bil column from the database at $row['bil'] .but i want you to help me by make it like row++ at bil column so that it will be 1 2 3 4 5 in ascending order.thanks.sorry for bad english

hicarl
  • 1
  • 3
  • `ALTER TABLE profil AUTO_INCREMENT = 1` will resit the primary key to 1 only if there are no larger values in the table.Besides,it DOES NOT MATTER if the increment doesn't start from 0. – Mihai Aug 23 '14 at 15:56
  • yup i know.but can you put the code that will count like : bil = 0; then echo bil++ at the 'bil' column? you can ignore the auto increment because i st AI in the database. – hicarl Aug 23 '14 at 16:01
  • Add a for loop and print that out insted of $row['bil']. – Mihai Aug 23 '14 at 16:03
  • where should i put that sir? im very weak in logic thinking – hicarl Aug 23 '14 at 16:05
  • I appreciate the bait,but I wont write it for you:Here is an example,get stronger in logical thinking by writing it yourself.http://www.tizag.com/phpT/forloop.php – Mihai Aug 23 '14 at 16:08
  • lol im not trying to bait anyone...im really bad in logical thinking..btw thanks for the answer.ill try do it first – hicarl Aug 23 '14 at 16:11
  • http://stackoverflow.com/questions/6087364/easier-way-to-get-counter-from-while-loop – Mihai Aug 23 '14 at 16:16
  • is it true by doing this? $bil = 1; while($row = mysql_fetch_array($query)) { Print ""; Print ''. $bil++ . ""; – hicarl Aug 23 '14 at 16:22
  • I think it will print 2 try starting it from 0.And stop asking and start doing,why dont you test it already? – Mihai Aug 23 '14 at 16:25
  • it print 0 in the first row. if $bil=1 it will print 1 in the first row. lol sorry if im asking too many.think my problem is solved. i should start from 1. – hicarl Aug 23 '14 at 16:27

0 Answers0