如何通过PHP在MySql表中从数字中回显类名

时间:2015-10-18 23:30:28

标签: php mysql

我希望你好!我真的需要帮助我的PHP脚本: 我有两个来自不同文件和HTML表单的类,如下所示。

1:registerForm.php

此表用于收集用户的信息,我将向您展示一些字段和代码

  <div class="form_sep">
     <label for="reg_input_name" class="req">Class:</label>
     <select name="class" id="class" class="form-control" data- 
     required="true">
      <option>Select class</option>
       <option value="1">Baby</option>
       <option value="2">Middle</option>
       <option value="3">Pre-unity</option>
       <option value="4">Grade one</option>
       <option value="6">Grade three</option>
       <option value="7">Grade four</option>
       <option value="8">Grade five</option>
       <option value="9">Grade six</option>
       <option value="10">Grade seven</option>
       </select></div>

如上所示,当用户选择时,让我们说“五年级”,数字8将保存到表格中,目前在浏览器上它显示的数字为studentReg.php文件中的类值,但我想转换/将这些数字返回到他们的班级名称中,以便用户可以看到一年级,二年级,三年级等等。

2:这是course.php类文件:

   <?php
     include_once("class.database.php"); 
   function selectStdreg()
    {
    $org_id = $_SESSION['org_id'];
    $sql = "SELECT * FROM student_reg WHERE org_id ='$org_id'";
    $result = $this->database->query($sql);
    $result = $this->database->result;
    $this->rows = array();
    while ($row = mysql_fetch_object($result)) {
        $this->rows[] = $row;
    }
    return $this->rows;
   }
      ?>

3:这是student_controller.php类文件,用于将数字返回到类名

 <?php

include_once("class.database.php");

 class student_controller
 {

  public static function admittedClax($jibu)

 {
        if ($jibu == 1) {
            return "Baby";
        } else if ($jibu == 2) {
            return "Middle";
        } else if ($jibu == 3) {
            return "Pre-unit";
        } else if ($jibu == 4) {
            return "Grade one";
        } else if ($jibu == 5) {
            return "Grade two";
        } else if ($jibu == 6) {
            return "Grade three";
        } else if ($jibu == 7) {
            return "Grade four";
        } else if ($jibu == 8) {
            return "Grade five";
        } else if ($jibu == 9) {
            return "Grade six";
        } else if ($jibu == 10) {
            return "Grade seven";
        } else {
            return "no such class";
        }

      }

   }

 ?>

4:这是用于创建对象的header.php文件

 <?php
  require_once("class/class.course.php");
  require_once("class/class.std_category.php");
  require_once("class/class.studentReg.php");
  require_once("class/class.student_controller.php");
  // objects
  $courseObj=new course;
  $std_categoryObj=new std_category;
  $studentAdmitObj=new studentReg;
  $stdController = new student_controller;
 ?>

5:用于显示学生信息的studentReg.php文件

    <?php
   include('inc/header.php');

  $stdcategorylist=$courseObj->selectStdreg($jibu);
  if(count($stdcategorylist)>0)
 {?>
    <div id="" style="display: flex; height: 180px; width: auto; overflow:    
   scroll" >
    <table id="resp_table" class="table toggle-square" data-  
   filter="#table_search" width="100%">
    <thead>
    <tr>

        <th data-toggle="true">Add_Date</th>
        <th data-toggle="true">Nationality</th>
        <th data-toggle="true">Birth Date</th>
        <th data-toggle="true">Gender</th>
        <th data-toggle="true">Religion</th>
        <th data-toggle="true">Class</th>
        <th data-toggle="true">Trans Route</th>
        <th data-toggle="true">Health</th>
        <th data-toggle="true">Father Name</th>
        <th data-toggle="true">Occupation</th>
        <th data-toggle="true">Office Adress</th>
        <th data-toggle="true">Mobile</th>
        <th data-toggle="true">Mother Name</th>
        <th data-toggle="true">Occupation</th>
        <th data-toggle="true">Office adress</th>
        <th data-toggle="true">Mobile</th>
    </tr>
    </thead>
    <tbody>
    <?php echo $nana = $stdController->admittedClax($jibu);  ?>

    <?php foreach($stdcategorylist as $list)   {?>
   <tr style="width: 100%">
    <td><?php echo $list->add_date; ?></td>
    <td><?php echo $list->country; ?></td>
    <td><?php echo $list->b_date; ?></td>
    <td><?php echo $list->gender; ?></td>
    <td><?php echo $list->religion; ?></td>

    // Am stacking here on this field       
    <td><?php echo $list->class; ?></td>


    <td><?php echo $list->roote; ?></td>
    <td><?php echo $list->h_prob; ?></td>
    <td><?php echo $list->pname_one; ?></td>
    <td><?php echo $list->pname_oneoccup; ?></td>
    <td><?php echo $list->pname_oneofc; ?></td>
    <td><?php echo $list->pname_onemob; ?></td>
    <td><?php echo $list->pname_two; ?></td>
    <td><?php echo $list->pname_two_occup; ?></td>
    <td><?php echo $list->pname_two_offc; ?></td>
    <td><?php echo $list->pname_two_mob; ?></td>
  </tr>
  <?php } ?>

    </tbody></div>
    <tfoot class="hide-if-no-paging">
    <tr>
        <td colspan="6" class="text-center">
            <ul class="pagination pagination-sm"></ul>
        </td>
    </tr>
    </tfoot>
  </table>
 <?php } ?>

注意:现在我在echo $ nana之后得到的不是这样的类

任何想知道如何组合/加入上述课程以获得理想答案的人我将不胜感激,并且对于许多解释和我的英语非常抱歉。

0 个答案:

没有答案