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.
Updated code is here
$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**
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.To overcome the OP's
li {float:left}
styling, he has made this adjustment in the css:ul{display: table-cell; }
Old answer starts here:
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%".
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:The error that I found in your post is that your table column is either
EventId
orEvent_Id
. You should fix this typo for clarity.Since you order by row_name you only need to check if the new value is different from the previous value.
You can use this function for
like
in phpExample