![](/img/trans.png)
[英]How can I select all id's from a sql table in descending order and then echo them (in php)?
[英]SQL PHP : How to select some column from sql database and display it in PHP/HTML generated table in descending order where condition is…
我有一個SQL表res
,其中包含一些行和列。 例如
Sno RegNo Name sub1 sub2 sub3 total percent result color
1 1DU12CS100 s1 10 10 10 30 50 fail danger
2 1DU12CS101 s2 20 20 20 60 80 pass success
3 1DU12CS102 s3 20 25 30 75 90 pass success
4 1DU12ME055 se 10 15 20 45 55 fail danger
5 1DU12IS044 as 20 20 30 70 80 pass success
6 1DU13CS077 sd 10 20 30 60 70 pass success
7 1DU14CS111 df 15 15 15 45 55 fail danger
8 1DU13ME006 fd 20 30 0 50 55 fail danger
9 1DU11CV123 my 20 20 20 30 70 pass success
10 1DU12CS444 yr 30 20 30 80 95 pass success
當有人將1DU12CS100
在form.html(GET方法)中輸入1DU12CS100
時,我想按total
的降序以php / html生成的表順序顯示結果。 結果應該看起來像
Rank Name RegNo Total Percent Result
1 yr 1DU12CS444 80 95 pass
2 s3 1DU12CS102 75 90 pass
3 s2 1DU12CS101 60 80 pass
4 s1 1DU12CS100 30 50 fail
我想要由引導程序樣式化的表。 如果結果為通過,則行應為綠色,如果結果為失敗,則行應為紅色...
1DU12CS100
應該首先獲取substr(res.RegNo,1,7).... [我認為]
form.html代碼是
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div id="wrap">
<form action="rank.php" class="form-horizontal" method="get">
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label" for="RegNo">Enter your Reg No :</label>
<div class="col-md-5">
<input id="RegNo" name="RegNo" value="" class="form-control input-md" required type="text">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" type="submit" value="Submit" class="btn btn-success">Get Rank</button>
</div>
</div>
</fieldset>
</form>
</body>
</html>
rank.php的代碼應該是什么?
從這里可以看到真實的視圖http://www.fastvturesults.com/classranking/1nh13cs001/394154679
除了錯誤檢查和安全性,基本知識是:
//get number from querystring
$regNo = $_GET['regNo'];
//get substring
$search = substring($regNo,0,7);
//create query
$sql = "SELECT * FROM `res` WHERE `RegNo` like '$search%' ORDER BY `Total` DESC";
創建html表只是循環結果和構建html的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.