2017-02-25 37 views
0

我有代码把信息消息用户着继续,如果行数是不正确的

if($rowcount1 > 0){ 
     ?> 
      <h3 class="text-muted"><u>DEPARTURE</u></h3> 
      <h4><?php echo "$origin to $destination "?></h4> 
       <table class="table table-hover"> 
        <thead> 
        <tr> 
         <th>FLIGHT NO.</th> 
         <th>DEPART</th> 
         <th>ARRIVE</th> 
         <th>AIRPORT</th> 
         <th>DURATION</th> 
         <th>FLY ONLY</th> 
         <th>FLY + BAGGAGE</th> 
        </tr> 
        </thead> 
        <tbody> 
        <?php 
         foreach ($query as $flightr) { 
          echo "<tr>"; 
          echo "<td>".$flightr['id']."</td>"; 
          echo "<td>".$flightr['depart']."</td>"; 
          echo "<td>".$flightr['arrive']."</td>"; 
          echo "<td>".$flightr['airport']."</td>"; 
          echo "<td>".$flightr['duration']."</td>"; 
          echo "<td> <label for=lbl7> <input type='radio' checked id='lbl7' name='flight[]' value='".$flightr['flyonly']."'> PHP ".number_format($flightr['flyonly'])."</label></td>"; 
          echo "<td> <label for=lbl8> <input type='radio' checked id='lbl8' name='flight[]' value='".$flightr['flybaggage']."'> PHP ".number_format($flightr['flybaggage'])."</label></td>"; 
          echo "</tr>"; 
         } 
        ?> 
        </tbody> 
       </table> 
       <hr> 
        <?php 

         }else{ 
          echo " <div class='alert alert-info' role='alert'> 
             No results found on <BIG class='text-muted'>Departure</BIG> pick another flight thank you. 
            </div> 
          "; 
         } 
     } 
     } 
    ?> 
    <button type="button" name="forform" onclick="" class="hit">hit</button> 

如何把信息消息着继续该用户(以及他们不能按一下按钮继续),如果数的行是不正确的。通过按钮点击。在js对不起。在此先感谢

回答

2

添加disabled根据rowCount时

按钮的属性
<button type="button" name="forform" onclick="" class="hit" 
     <?php echo ($rowcount1 > 0) ? '' : 'disabled'; ?>>hit</button> 
+0

更好然后地雷 – urfusion

+0

仍可继续,因为我的按钮类上有一个js脚本'点击'也许js函数重写它?我该怎么做? –

+0

如果按钮被禁用,那么点击脚本将不会执行 – Naincy

0

你可以做到这一点的放按钮,如果用禁用的属性else条件

if ($rowcount1 > 0) { 
    ?> 
    <h3 class="text-muted"><u>DEPARTURE</u></h3> 
    <h4><?php echo "$origin to $destination " ?></h4> 
    <table class="table table-hover"> 
     <thead> 
      <tr> 
       <th>FLIGHT NO.</th> 
       <th>DEPART</th> 
       <th>ARRIVE</th> 
       <th>AIRPORT</th> 
       <th>DURATION</th> 
       <th>FLY ONLY</th> 
       <th>FLY + BAGGAGE</th> 
      </tr> 
     </thead> 
     <tbody> 
    <?php 
    foreach ($query as $flightr) { 
     echo "<tr>"; 
     echo "<td>" . $flightr['id'] . "</td>"; 
     echo "<td>" . $flightr['depart'] . "</td>"; 
     echo "<td>" . $flightr['arrive'] . "</td>"; 
     echo "<td>" . $flightr['airport'] . "</td>"; 
     echo "<td>" . $flightr['duration'] . "</td>"; 
     echo "<td> <label for=lbl7> <input type='radio' checked id='lbl7' name='flight[]' value='" . $flightr['flyonly'] . "'> PHP " . number_format($flightr['flyonly']) . "</label></td>"; 
     echo "<td> <label for=lbl8> <input type='radio' checked id='lbl8' name='flight[]' value='" . $flightr['flybaggage'] . "'> PHP " . number_format($flightr['flybaggage']) . "</label></td>"; 
     echo "</tr>"; 
    } 
    ?> 
     </tbody> 
    </table> 
    <hr> 
    <button type="button" name="forform" onclick="" class="hit">hit</button> 
    <?php 
} else { 
    echo " <div class='alert alert-info' role='alert'> 
             No results found on <BIG class='text-muted'>Departure</BIG> pick another flight thank you. 
            </div> 
          "; 
    echo '<button type="button" name="forform" onclick="" class="hit" disable="disable">hit</button>'; 
} 
?>