dougan1465 2015-07-04 07:32
浏览 55

使用php,jquery基于条件自动生成字符串变量

I am working on a student user registration system, whereby a new student is assigned a registration number depending on his department.

The following students are studying mechanical engineering (one student-ID per line):

BSME/010J/2012
BSME/011J/2012
BSME/012J/2012

Only the middle area changes (010,011,012,013...). The last part is the current year.

Each department has a unique way of giving registration numbers. Is there a way a php code can generate these registration numbers based on a value one selects on the option? the following is my form:

<form method="post" action="" id="myForm"
    <select>
    <option>Mechanical</option>
    <option>Bcom</option>
    <button id="submit">Generate</button>
</form>
  • 写回答

1条回答 默认 最新

  • drc4925 2015-07-04 08:37
    关注

    Assuming that a string always starts or ends with the same sequence (in this example: j) and has a number that is incremented, then you could request a custom sequence, in which a separate sequence may distinguish different types of students in this case (For example: F for freshman, SM for sophomore, J for Junior, SR for Senior, and C for continuing student). As long as you have a separate variable representing an integer, you could increment that number and concatenate the strings to produce the final unique string:

    HTML

    <!-- Form -->
    <form action="process.php" method="GET" \>
    <!-- Select Department -->
    <select name="department">
    <option value="BSME">What Ever this stands for</option>
    <option value="nextD">Next Department</option>
    <option value="anotherD">Another Department</option>
    </select>
    
    <!-- Enter Year (Not sure how this is determine, assuming input) -->
    <input type="text" name="year" />
    
    <!-- Apply Custom Sequence -->
    <input type="text" name="customSequence" /> 
    
    <!-- SUBMITION - Call Processing -->
    <button type="submit" value="Generate" />
    </form>
    

    **PHP - process.php **

    // Initialize Values
    $departmentFromSelect = $_GET['department'];
    $yearFromForm = $_GET['year'];
    $valueFromSequenceInput = $_GET['customSequence'];
    // INTEGER TO INCREMENT WOULD HAVE TO BE STATIC OR GLOBAL
    public static $integerToIncrement = 0;
    
    // Call the function passing to generate next reg number
    function generateRegistrationNumber() {
        // Increment integer for next value
        $integerToIncrement++;
        // Concatenate String
        $finalRegNum = $departmentFromSelect . "/" . $integerToIncrement . $valueFromSequenceInput . "/" . $year;
        return $finalRegNum;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等