0

我有一个带有“id”的表,每次将新条目添加到表中时都会自动递增。在同一张表中,我还存储图像。

无论增加图像的 id 是什么,它总是相同的。

我希望图像根据“id”进行更改。我如何实现这一目标?在下面找到我的代码文件:displayImage.php:

$link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());

// select our database
mysql_select_db("flightSched") or die(mysql_error());

// get the image from the db
$sql = "SELECT image FROM flightSched";

// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());

// set the header for the image
header("Content-type: image/jpeg");
echo mysql_result($result,1);

// close the db link
mysql_close($link);

以及带有递增“id”的代码

$result = mysql_query("SELECT id, flightNo, airline, origin, arrivalTime, status 
                       FROM flightSched ") 
    or die(mysql_error());  

    $variable= 'id=basicBoard';
    //echo $variable;


    echo "<table border='1' id='customers'>";
    echo "<tr> <th></th> <th>Flight No</th> <th>Airline</th> <th>Origin</th> <th>Arrival</th> <th>Status</th> ";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row into a table
        echo "<tr " . $variable . "><td>"; 

        echo '<img src="displayImage.php?id=' . $row['id'] . ' " width="40" height="40" >';
        echo "</td><td>"; 
        echo $row['flightNo'];
        echo "</td><td>"; 
        echo $row['airline'];
        echo "</td><td>"; 
        echo $row['origin'] . $row['id'];
        echo "</td><td>"; 
        echo $row['arrivalTime'];
        echo "</td><td>"; 
        echo $row['status'];
        echo "</td></tr>"; 

        if ($variable == 'id=basicBoard')
            {
            $variable = 'class=alt';
            //echo $variable;
            } 
        elseif ($variable == 'class=alt')
            {
            $variable = 'id=basicBoard';
            //echo $variable;
            } 
        } 

        echo "</table> <br/> <br/>";

期待你的答复。任何帮助是极大的赞赏!

4

1 回答 1

0

您没有使用 ID 来限制 displayImage.php 文件中的结果。

改变

$sql = "SELECT image FROM flightSched";

$sql = "SELECT image FROM flightSched WHERE id = '$_GET[id]'";

这将使它工作,但只是一个示例,但请清理 GET 值,而不是直接在 sql 中使用它。

于 2013-10-10T09:55:16.093 回答