简体   繁体   中英

SQL PHP : How to select some column from sql database and display it in PHP/HTML generated table in descending order where condition is…

I have a sql table res which contains some rows and column. For example

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

When someone will enter 1DU12CS100 in form.html (GET Method), I want to display the result in php/html generated table order by total in descending order. The result should look like

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

I want the table styled by bootstrap. If the result is pass then row should be green, if result is fail then row should be red...

1DU12CS100 should first get substr( res.RegNo, 1, 7 ) .... [ I think ]

The form.html code is

<!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>

What should be code for rank.php ?

A realistic view can be seen from here http://www.fastvturesults.com/classranking/1nh13cs001/394154679

Error checking and security aside, the basics are:

//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";

Creating the html table is just a matter of looping the results and building the html.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM