0
我有一個「id」表,每次向表中添加一個新條目時都會自動遞增。在同一張表中,我也存儲圖像。我如何根據ID生成MySQL表中的映像
不管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/>";
代碼期待您的回覆。 任何幫助,非常感謝!
如果我通過表單填入「id」,那麼您的解決方案本來就很棒,但我沒有。限制通過查詢進行。 – SirBT
在你的圖像src中,你可以做'displayImage.php?id ='。 $ row ['id']。 ''''這是添加'?id ='到displayImage php文件,這可以通過'$ _GET ['id']'displayImage.php裏面訪問' –
它的工作原理非常好...謝謝對我清楚。 – SirBT