我一直在尝试一段时间来弄清楚如何根据ID来显示数据库中特定行的数据。显示特定ID的数据
说我想要的链接是survivaloperations.net/page/mso?p=contracts & ID =#
其中id =#是我从数据库中提取数据行的ID
如何使用上面显示的链接从数据库中提取和显示数据?
我试图谷歌,但真的不知道该怎么谷歌找到相关的东西
任何帮助或引用链接表示赞赏!
这是我曾尝试:
<?php
if ($p == contracts) {
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; // if $_GET['id'] exists, return it as an integer, otherwise use a sentinel, id's usually start with 1, so 0 works
if ($id != 0):
// I assume this is a specific news item meaning you know it's ONE result
$query = 'SELECT * FROM contracts WHERE id=' . $id . ' LIMIT 1'; // so try to use limit 1, no need to add extra steps in the database lookup
endif;
mysql_select_db('survival_contracts');
$result = mysql_query($query);
//$result = mysql_query($query) or die(mysql_error());
// now loop through the results
while ($row = mysql_fetch_array($result)) {
// and use'em however you wish
echo("<div class='mso_body_wrap'>
<div id='mso_news_container'>
<div class='mso_news_wrap'>
<div class='mso_news_top'>$row2[contract_type]</div>
<div class='mso_news_poster'>
<div class='mso_poster_avatar'><img src='images/tank.jpg'></div>
<div class='mso_poster_info'>for <a
href='#'>$row2[unit]</a><br/>by: <a
href='http://www.survivaloperations.net/user/$row2[userid]-$row2[username]/'>$row2[username]</a>
</div>
</div>
<div class='mso_news_content'>
<div class='mso_news_body'>
Callsign: $row2[callsign]<br/>
Urgency: $row2[urgency]<br/>
Location: $row2[location]<br/>
Grid: $row2[grid]<br/>
Enemy Activity: $row2[enemy_activity]<br/>
Hours Since Lasrt Contact: $row2[contact_hours]<br/><br/>
Supplies Requested: $row2[supplies]<br/>
Comments: $row2[comments]
</div>
</div>
<div class='mso_news_bottom'></div>
</div>
</div>");
}
?>
你必须至少尝试的东西,然后张贴在这里进行修订的建议,否则这只是一个请求代码。检查这个PHP和MySql部分:http://www.w3schools.com/php/php_mysql_select.asp – MahanGM
[**如何显示数据库中特定行的数据**](https://www.google。 CA /搜q =如何+显示器+数据+从+ A +的具体+行+ +我+数据库中++ PHP与IE = UTF-8&OE = UTF-8&RLS = org.mozilla:EN-US:官方与客户端=火狐-a&channel = np&source = hp&gws_rd = cr)大约有47900000个结果(0.44秒) –