0

hi friends,

I used following code for automatically incrementing value and stored in database. This working but it have small problem. when I submit value then only incrementing. ex, i entered details for invoice number 2, but it showing invoice number 1.

 <?php

       mysql_connect("localhost","root","") or die(mysql_error());
   mysql_select_db("menus") or die(mysql_error());
   $query2=mysql_query("select invoiceno from bill");

    while($row=mysql_fetch_array($query2))
      {
       $var=$row['invoiceno'];
      }
     $count=$var+1;
     echo $count;

  ?>

anybody knowing result for pls help to me.

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

select max(invoiceno) from bill
OR
You may set invoiceno column to AUTO_INCREMENT in MYSQL, it will automatically insert new id.

Edited by urtrivedi: n/a

0

Use AUTO_INCREMENT/ Primay key for the invoice number field. That is a structure way to maintaining table with unique id. While setting primary key for invoice number, it automatically checks for the duplication and never allowed.

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.