dptsivmg82908 2014-03-07 13:21
浏览 35
已采纳

Re:自动生成自动增量编号

I tried to conclude the tread I started last time on how to Auto generate serial numbers as seen here Auto generate serial numbers. On my own I have been able to come out with a code that give me what I want.

Using this line of code

   SELECT COUNT(donor_id) + 1 AS Counter
   FROM tbl_donors

I got the value I want which is 6+1; i.e. 6 being the total number of records and 1 is the additional for the new record. But now how to add it to the tableset that will show all the values as seen here http://www.netdataflow.com/rbme/ is where I am having a problem. I am using dreamweaver to builder my tableset and below is the tableset code

<div align="center">
  <table width="1100" border="0" cellpadding="0" cellspacing="0">
    <tr id="colhead">
      <td width="30" height="30" id="labels"><div align="center"><strong>ID</strong> 
 </div></td>
      <td width="200" height="30" id="labels"><div align="center"><strong>Donor  
Name</strong></div></td>
      <td width="100" height="30" id="labels"><div align="center"> 
<strong>Designation</strong></div></td>
      <td width="250" height="30" id="labels"><div align="center">
<strong>Address</strong></div></td>
      <td width="80" height="30" id="labels"><div align="center"><strong>City</strong>
</div></td>
      <td width="80" height="30" id="labels"><div align="center"><strong>State</strong>
</div></td>
      <td width="80" height="30" id="labels"><div align="center">
<strong>Country</strong></div></td>
      <td width="100" height="30" id="labels"><div align="center"><strong>Phone</strong>
</div></td>
      <td width="150" height="30" id="labels"><div align="center"><strong>Email 
Address</strong></div></td>
    </tr>
    <?php do { ?>
      <tr <?php 
 // technocurve arc 3 php bv block2/3 start
echo " style=\"background-color:$color\"";
// technocurve arc 3 php bv block2/3 end
?> id="rowlines">
        <td id="labels"><div align="center"><?php echo $row_rsdonors['donor_id']; ?>  
</div></td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['donorname']; ?>
</div></td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['designation']; ?>
</div></td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['address']; ?>
</div></td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['city']; ?></div>
</td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['state']; ?></div>
</td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['country']; ?>
</div></td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['phone']; ?></div>
</td>
        <td id="labels"><div align="center"><?php echo $row_rsdonors['emailaddr']; ?>
</div></td>
      </tr>
      <?php 
// technocurve arc 3 php bv block3/3 start
if ($color == $color1) {
$color = $color2;
} else {
$color = $color1;
 }

Can anyone help out? If possible, I will want to add to the

 SELECT COUNT(donor_id) + 1 AS Counter
 FROM tbl_donors

to the first row of the table before the ID. I am open to any other idea or way or doing it, possibly manually coding the table instead of using dreamweaver dynamic tableset.

I appreciate you help in advance.

Mike

  • 写回答

2条回答 默认 最新

  • dqkv0603 2014-03-08 22:10
    关注

    I have been able to get the right code for my questions on "Auto generate Auto Increment numbers". I think the issue I had was the title to my question. The right title should have been "How to generate table row numbers"

    Anyway find below the code I used. Here is the reference link: With MySQL, how can I generate a column containing the record index in a table?

    SELECT  d.*, @curRow := @curRow + 1 AS row_number
    FROM    tbl_donors d
    JOIN    (SELECT @curRow := 0) r
    WHERE user_name = %s"  **//*Please dont add this WHERE clause if you don't need it. In my case I filter records based on the person who entered it hence the WHERE clause** 
    

    But because I am using Dreamweaver, Dreamweaver changed it to this format:

    mysql_select_db($database_yourdatabasename, $yourdatabasename);
    $query_rsdonors = sprintf("SELECT  d.*, @curRow := @curRow + 1 AS row_number 
    FROM tbl_donors d JOIN    (SELECT @curRow := 0) r WHERE user_name = %s",  
    GetSQLValueString($colname_rsdonors, "text"));
    $query_limit_rsdonors = sprintf("%s LIMIT %d, %d", $query_rsdonors, $startRow_rsdonors,   
    1$maxRows_rsdonors);
    $rsdonors = mysql_query($query_limit_rsdonors, $ProjMonEva) or die(mysql_error());
    $row_rsdonors = mysql_fetch_assoc($rsdonors);
    

    Here is the table code structure

    <div align="center">
      <table width="1130" border="0" cellpadding="0" cellspacing="0">
        <tr id="colhead">
          <td width="30" height="30" id="labels"><strong>SN</strong></td>
          <td width="30" height="30" id="labels"><div align="center"><strong>ID</strong>  
    </div></td>
          <td width="200" height="30" id="labels"><div align="center"><strong>Donor 
    Name</strong></div></td>
          <td width="100" height="30" id="labels"><div align="center">
    <strong>Designation</strong></div></td>
          <td width="250" height="30" id="labels"><div align="center">
    <strong>Address</strong></div></td>
          <td width="80" height="30" id="labels"><div align="center"><strong>City</strong>
    </div></td>
          <td width="80" height="30" id="labels"><div align="center"><strong>State</strong>
    </div></td>
          <td width="80" height="30" id="labels"><div align="center">
    <strong>Country</strong></div></td>
          <td width="100" height="30" id="labels"><div align="center"><strong>Phone</strong>
    </div></td>
          <td width="150" height="30" id="labels"><div align="center"><strong>Email 
    Address</strong></div></td>
        </tr>
        <?php do { ?>   
          <tr <?php 
    // technocurve arc 3 php bv block2/3 start
    echo " style=\"background-color:$color\"";
    // technocurve arc 3 php bv block2/3 end
    ?>id="rowlines">
            <td id="labels"><?php echo $row_rsdonors['row_number']; ?></td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['donor_id']; ?>
    </div></td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['donorname']; ?>
    </div></td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['designation']; ?>
    </div></td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['address']; ?>
    </div></td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['city']; ?></div>
    </td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['state']; ?></div>
    </td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['country']; ?>
    </div></td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['phone']; ?></div>
    </td>
            <td id="labels"><div align="center"><?php echo $row_rsdonors['emailaddr']; ?>
    </div></td>
          </tr>
          <?php 
    // technocurve arc 3 php bv block3/3 start
    if ($color == $color1) {
    $color = $color2;
    } else {
    $color = $color1;
    }
    

    Here is a brief of what I am getting

    SN       Donor Name              Designation
     1    Mr Michael Nwuzor       Chief Consultant
     2    Mr Michael Nwuzor       Chief Consultant
     3    South-Sea Datcomm Ltd
    

    Here is the link from where I was able to get the right code: With MySQL, how can I generate a column containing the record index in a table?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?