无法显示一行数据

时间:2015-05-12 07:07:11

标签: php html mysql

Check this

我是这个的新手,我不知道为什么“详情”选项卡上没有显示任何内容,但我确实成功地将数据插入到数据库中。有人可以帮我这个吗?

<?php
require ("Data/TaxiData.php");


class TaxiController {

function CreateOverviewTable() {
    $result = "
        <table class='overViewTable'>
            <tr>
                <td></td>
                <td></td>
                <td><b>Id</b></td>
                <td><b>Name</b></td>
                <td><b>Gender</b></td>
                <td><b>Faculty</b></td>
                <td><b>CarType</b></td>
                <td><b>Car Plate Number</b></td>
                <td><b>Price</b></td>
                <td><b>Detail</b></td>
            </tr>";

    $itaxiArray = $this->GetitaxiByType('%');

    foreach ($itaxiArray as $key => $value) {
        $result = $result .
                "<tr>
                    <td><a href='Add.html?update=$value->id'>Update</a></td>
                    <td><a href='#' onclick='showConfirm($value->id)'>Delete</a></td>
                    <td>$value->id</td>
                    <td>$value->name</td>
                    <td>$value->gender</td>    
                    <td>$value->faculty</td> 
                    <td>$value->type</td>
                    <td>$value->plate</td>
                    <td>$value->price</td>
                    <td>$value->detail</td>
                </tr>";
    }

    $result = $result . "</table>";
    return $result;
}

function CreateitaxiDropdownList() {
    $TaxiData = new TaxiData();
    $result = "<form action = '' method = 'post' width = '200px'>
                Please select a type: 
                <select name = 'types' >
                    <option value = '%' >All</option>
                    " . $this->CreateOptionValues($this->GetitaxiTypes()) .
            "</select>
                 <input type = 'submit' value = 'Search' />
                </form>";

    return $result;
}

function CreateOptionValues(array $valueArray) {
    $result = "";

    foreach ($valueArray as $value) {
        $result = $result . "<option value='$value'>$value</option>";
    }

    return $result;
}

function CreateitaxiTables($types) {
    $TaxiData = new TaxiData();
    $itaxiArray = $TaxiData->GetitaxiByType($types);
    $result = "";


    foreach ($itaxiArray as $key => $itaxi) {
        $result = $result .
                "<table class = 'itaxiTable'>
                    <tr>
                        <th rowspan='6' width = '150px' ><img runat = 'server' src = '$itaxi->image' /></th>
                        <th width = '75px' >Name: </th>
                        <td>$itaxi->name</td>
                    </tr>

                    <tr>
                        <th>Gender: </th>
                        <td>$itaxi->gender</td>
                    </tr>

                    <tr>
                        <th>Faculty: </th>
                        <td>$itaxi->faculty</td>
                    </tr>

                    <tr>
                        <th>Car type: </th>
                        <td>$itaxi->type</td>
                    </tr>

                    <tr>
                        <th>Car Plate: </th>
                        <td>$itaxi->plate</td>
                    </tr>

                    <tr>
                        <th>Detail: </th>
                        <td>$itaxi->detail</td>
                    </tr>


                 </table>";
    }
    return $result;
}

function GetImages() {

    $handle = opendir("Images/ump");


    while ($image = readdir($handle)) {
        $images[] = $image;
    }

    closedir($handle);


    $imageArray = array();
    foreach ($images as $image) {
        if (strlen($image) > 2) {
            array_push($imageArray, $image);
        }
    }


    $result = $this->CreateOptionValues($imageArray);
    return $result;
}   



function Insertitaxi() {
    $name = $_POST["txtName"];
    $gender = $_POST["txtGender"];
    $faculty = $_POST["txtFaculty"];
    $type = $_POST["txtCar Type"];
    $plate = $_POST["txtCar Plate Number"];
    $price = $_POST["txtPrice"];
    $detail = $_POST["txtDetail"];


    $itaxi = new TaxiEntity(-1, $name, $gender, $faculty, $type, $plate, $price);
    $TaxiData = new TaxiData();
    $TaxiData->Insertitaxi($itaxi);
}

function Updateitaxi($id) {
   $name = $_POST["txtName"];
    $gender = $_POST["txtGender"];
    $faculty = $_POST["txtFaculty"];
    $type = $_POST["ddlCar Type"];
    $plate = $_POST["txtCar Plate Number"];
    $price = $_POST["txtPrice"];
     $detail = $_POST["txtDetail"];

     $itaxi = new TaxiEntity(-1, $name, $gender, $faculty, $type, $plate, $price, $detail);
    $TaxiData = new TaxiData();
    $TaxiData->Updateitaxi($id, $itaxi);
}

function Deleteitaxi($id) 
{
    $TaxiData = new TaxiData();
    $TaxiData->Deleteitaxi($id);
}


function GetitaxiById($id) {
   $TaxiData = new TaxiData();
    return $TaxiData->GetitaxiById($id);
}

function GetitaxiByType($type) {
   $TaxiData = new TaxiData();
    return $TaxiData->GetitaxiByType($type);
}

function GetitaxiTypes() {
  $TaxiData = new TaxiData();
    return $TaxiData->GetitaxiTypes();
}

}
?>

所以,这是TaxiData.php。也许这里出了问题。

    <?php

require(“Entities / TaxiEntity.php”);

类TaxiData {

function GetitaxiTypes() {
    require ('mysql_connect.php');

    mysql_connect($db_host, $db_username, $db_pass) or die(mysql_error());
    mysql_select_db($db_name);
    $result = mysql_query("SELECT DISTINCT type FROM itaxi") or die(mysql_error());
    $types = array();


    while ($row = mysql_fetch_array($result)) {
        array_push($types, $row[0]);
    }


    mysql_close();
    return $types;
}


function GetitaxiByType($type) {
    require ('mysql_connect.php');

    mysql_connect($db_host, $db_username, $db_pass) or die(mysql_error());
     mysql_select_db($db_name);

    $query = "SELECT * FROM itaxi WHERE type LIKE '$type'";
    $result = mysql_query($query) or die(mysql_error());
    $TaxiArray = array();


    while ($row = mysql_fetch_array($result)) {
        $id = $row[0];
        $name = $row[1];
        $gender = $row[2];
        $faculty = $row[3];
        $type = $row[4];
        $plate = $row[5];
        $price = $row[6];
        $detail = $row[7];



      $itaxi = new TaxiEntity($id, $name, $gender, $faculty, $type, $plate, $price, $detail);
        array_push($TaxiArray, $itaxi);
    }

    mysql_close();
    return $TaxiArray;
}

function GetitaxiById($id) {
    require ('mysql_connect.php');

     mysql_connect($db_host, $db_username, $db_pass) or die(mysql_error());
     mysql_select_db($db_name);

    $query = "SELECT * FROM itaxi WHERE id = $id";
    $result = mysql_query($query) or die(mysql_error());


    while ($row = mysql_fetch_array($result)) {
        $name = $row[1];
        $gender = $row[2];
        $faculty = $row[3];
        $type = $row[4];
        $plate = $row[5];
        $price = $row[6];
        $detail = $row[7];


       $itaxi = new TaxiEntity($id, $name, $gender, $faculty, $type, $plate, $price, $detail);
    }

    mysql_close();
    return $itaxi;
}

function Insertitaxi(TaxiEntity $itaxi) {
    $query = sprintf("INSERT INTO itaxi
                      (name, gender, faculty,type,plate,price,detail)
                      VALUES
                      ('%s','%s','%s','%s','%s','%s','%s','%s')",
            mysql_real_escape_string($itaxi->name),
            mysql_real_escape_string($itaxi->gender),
            mysql_real_escape_string($itaxi->faculty),
            mysql_real_escape_string($itaxi->type),
            mysql_real_escape_string($itaxi->plate),
            mysql_real_escape_string($itaxi->price),
             mysql_real_escape_string($itaxi->detail));
    $this->PerformQuery($query);
}

function Updateitaxi($id, TaxiEntity $itaxi) {
    $query = sprintf("UPDATE itaxi
                        SET name = '%s', gender = '%s', faculty = '%s', type = '%s',
                        price = '%s', detail = '%s'
                      WHERE id = $id",
           mysql_real_escape_string($itaxi->name),
            mysql_real_escape_string($itaxi->gender),
            mysql_real_escape_string($itaxi->faculty),
            mysql_real_escape_string($itaxi->type),
            mysql_real_escape_string($itaxi->plate),
            mysql_real_escape_string($itaxi->price),
             mysql_real_escape_string($itaxi->detail));

    $this->PerformQuery($query);
}

function Deleteitaxi($id) {
    $query = "DELETE FROM itaxi WHERE id = $id";
    $this->PerformQuery($query);
}

function PerformQuery($query) {
   require ('mysql_connect.php');

     mysql_connect($db_host, $db_username, $db_pass) or die(mysql_error());
     mysql_select_db($db_name);


    mysql_query($query) or die(mysql_error());
    mysql_close();
}

} ?&GT;

谢谢!

更新: 这是数据库 database

这是调试后得到的 outcome of debugging

1 个答案:

答案 0 :(得分:1)

看起来你错过了一些代码

function Insertitaxi() {
    $name = $_POST["txtName"];
    $gender = $_POST["txtGender"];
    $faculty = $_POST["txtFaculty"];
    $type = $_POST["txtCar Type"];
    $plate = $_POST["txtCar Plate Number"];
    $price = $_POST["txtPrice"];
    $detail = $_POST["txtDetail"];


    $itaxi = new TaxiEntity(-1, $name, $gender, $faculty, $type, $plate, $price);
    $TaxiData = new TaxiData();
    $TaxiData->Insertitaxi($itaxi);
}

这条线  $itaxi = new TaxiEntity(-1, $name, $gender, $faculty, $type, $plate, $price); 看起来应该是这样  $itaxi = new TaxiEntity(-1, $name, $gender, $faculty, $type, $plate, $price, $detail);

通过它的外观错过了最后的字段$ detail。试一试。

更新 - 还可以尝试将缺失的印版固定在其他功能上 -

function Updateitaxi($id, TaxiEntity $itaxi) {
    $query = sprintf("UPDATE itaxi
                        SET name = '%s', gender = '%s', faculty = '%s', type = '%s',
                        price = '%s', detail = '%s'
                      WHERE id = $id",
           mysql_real_escape_string($itaxi->name),
            mysql_real_escape_string($itaxi->gender),
            mysql_real_escape_string($itaxi->faculty),
            mysql_real_escape_string($itaxi->type),
            mysql_real_escape_string($itaxi->plate),
            mysql_real_escape_string($itaxi->price),
             mysql_real_escape_string($itaxi->detail));

    $this->PerformQuery($query);
}

将更新更改为包括plate =%s

"UPDATE itaxi SET name = '%s', gender = '%s', faculty = '%s', type = '%s', plate = '%s', price = '%s', detail = '%s' WHERE id = $id",