1

请大家帮助我了解我的代码的语法

<?php
    $detail = mysql_query("SELECT O.geoLocation, O.vehicleId, O.date, OL.oCodeDescription, V.vMake, V.vModel, V.colour
                            FROM offense O, offenselist OL, vehicle V 
                            WHERE OL.oCode = O.offenseListId AND O.offenderNatId =  '$id' AND V.vehicleReg = O.vehicleId");

    while($db_field = mysql_fetch_assoc($detail)){
        $geo = $db_field['O.geoLocation'];
        $vid = $db_field['O.vehicleId'];
        $date = $db_field['O.date'];
        $offense = $db_field['OL.oCodeDescription'];                                                    
        $make = $db_field['V.vMake'];
        $model = $db_field['V.vModel'];
        $colour = $db_field['V.colour'];
        echo"   <tr><td>Date:</td><td>$date</td></tr>
                <tr><td>Offense</td><td>$offense</td></tr>
                <tr><td>Scene Location:</td><td>$geo</td></tr>
                <tr><td>Vehicle Registration No.:</td><td>$vid</td></tr>                                                        
                <tr><td>Vehicle Description:</td><td>$colour $make $model</td></tr>
                <tr><td colspan='2'>&nbsp;</td></tr>
                <tr><td colspan='2'>&nbsp;</td></tr>";

    }
?>

它返回此错误之一:

未定义索引:第 142 行 C:\wamp\www\eroad\view.php 中的 O.geoLocation

4

2 回答 2

0

您需要加入两个表之间共有的 ID,例如:

$detail = mysql_query(
    "SELECT O.geoLocation, O.vehicleId, O.date, OL.oCodeDescription, V.vMake, V.vModel, V.colour
    FROM offense O 
    INNER JOIN offenselist OL 
        ON O.offenseListId = OL.oCode
    INNER JOIN vehicle V 
        ON O.vehicleId = V.vehicleReg
    WHERE O.offenderNatId = '$id'" 
);

应该做的伎俩。

于 2013-04-23T20:29:53.690 回答
0

我想你只需要输入$db_field['geoLocation'];而不是$db_field['O.geoLocation'];

于 2013-04-23T20:40:31.613 回答