如何在每个记录后添加case语句以添加break? [英] How to add case statement to add break after every record?
问题描述
在查找LIKE 'B%'
的下一条记录时,在每行LIKE 'A%'
之后都应有一个中断.
There should be a break after every row LIKE 'A%'
when find next records of LIKE 'B%'
.
$stmt = $con->prepare("SELECT * FROM fistevent WHERE Event_Id=? AND TicketType=? AND row_name REGEXP '^[A-Z]' ORDER BY row_name ASC");
$stmt->bind_param("ss", $_POST['EventId'],$_POST['TicketType']);
$stmt->execute();
$result = $stmt->get_result();
$numRows = $result->num_rows;
if($numRows > 0) {
echo ' <div class="register">';
while($r = $result->fetch_assoc()) {
$EvntId = $r['Event_Id'];
$RowName = $r['row_name'];
echo '<ul id="sub" class="sub">';
if($r['seats'] == null){
echo '<li class="BlankSeat" ></li>';
}elseif($r['Status'] == 'Y' || $r['Status'] == 'Hold'){
echo '<li class="occupied" title="Row'.$r["seats"].'" name="'.$RowName.'" value="'.$r["seats"].'"></li>';
}else{
echo '<li class="Available" title="Row'.$r["seats"].'" name="'.$RowName.'" value="'.$r["seats"].'"></li>';
}
echo "</ul>";
}
echo '</div>';
I am getting the following output, but I want after `LIKE 'A%'` the next `LIKE 'B%'` should be in the next row.
更新的代码在这里
$stmt = $con->prepare("SELECT * FROM fistevent WHERE Event_Id=? AND TicketType=? AND row_name REGEXP '^[A-Z]' ORDER BY row_name ASC");
$stmt->bind_param("ss", $_POST['EventId'],$_POST['TicketType']);
$stmt->execute();
$result = $stmt->get_result();
$numRows = $result->num_rows;
if($numRows > 0) {
echo ' <div class="register">';
$prev='A';
while($r = $result->fetch_assoc()) {
$EvntId = $r['Event_Id'];
$RowName = $r['row_name'];
if($prev!=$RowName){
echo "<br>";
$prev=$RowName;
}
echo '<ul id="sub" >';
if($r['seats'] == null){
echo '<li class="BlankSeat" ></li>';
}elseif($r['Status'] == 'Y' || $r['Status'] == 'Hold'){
echo '<li class="occupied" title="Row'.$r["seats"].'" name="'.$RowName.'" value="'.$r["seats"].'"></li>';
}else{
echo '<li class="Available" title="Row'.$r["seats"].'" name="'.$RowName.'" value="'.$r["seats"].'"></li>';
}
echo "</ul>";
}
echo '</div>';
}else{
echo "No seats Available";
}
**in responsive**
推荐答案
这应该在每个唯一行之间(而不是在第一行之前)添加换行符,并将row_name
字母添加到每个唯一行的开头.>
This should add line breaks between (not before the first) each unique row, and add the row_name
letter to the start of each unique row.
$prev='';
while($r=$result->fetch_assoc()) {
if($prev!=$r['row_name']){
if($prev!=''){echo "<br>";} // add breaks between rows
echo "<ul id=\"sub\" class=\"sub\">{$r['row_name']} "; // label the row
$prev=$r['row_name']; // store new row_name letter
}else{
echo "<ul id=\"sub\" class=\"sub\">"; // not a new row_name, extend existing row
}
if($r['seats']==null){
echo "<li class=\"BlankSeat\"></li>";
}elseif($r['Status']=='Y' || $r['Status']=='Hold'){
echo "<li class=\"occupied\" title=\"Row{$r['seats']}\" name=\"{$r['row_name']}\" value=\"{$r["seats"]}\"></li>";
}else{
echo "<li class=\"Available\" title=\"Row{$r['seats']}\" name=\"{$r['row_name']}\" value=\"{$r['seats']}\"></li>";
}
echo "</ul>";
}
为克服OP的li {float:left}
样式,他在CSS中进行了此调整:
To overcome the OP's li {float:left}
styling, he has made this adjustment in the css:
ul{display: table-cell; }
旧答案从这里开始:
我不知道Bijender的答案如何帮助您,也不知道您为什么需要函数调用.我也不知道您所说的在'A%之后添加休息时间"是什么意思.
I don't know how Bijender's answer helped you, and I don't know why you need a function call. I also don't know what you mean by "add break after LIKE 'A%".
由于row_name
是单个字母值,并且您只想返回具有值A,B,C,D,E,F,G,H,I或J的行,所以您将需要这种更简单的方法/更精细的查询:
Since row_name
is a single letter value, and you want to only return rows with the value A, B, C, D, E, F, G, H, I, or J, then you will want this simpler / more refined query:
SELECT *
FROM fistevent
WHERE Event_Id=? AND TicketType=? AND row_name IN ('A','B','C','D','E','F','G','H','I','J')
ORDER BY row_name ASC
我在您的帖子中发现的错误是您的表列是EventId
或Event_Id
.为了清楚起见,您应该修正此错字.
The error that I found in your post is that your table column is either EventId
or Event_Id
. You should fix this typo for clarity.
这篇关于如何在每个记录后添加case语句以添加break?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!