如果值为categories =“”,如何打破跳过循环?

This my script , I want to skip the loop if value of categories="" in the database. How could I do that ??

   public function display_international( ) {
                $query = 'SELECT *
      FROM
       tourDB
      WHERE 
        tour_type = "international"';
               $result = mysql_query( $query ) or die( mysql_error() );
                  if ( $result !== false && mysql_num_rows( $result ) > 0 ) {
                       while ( $i = mysql_fetch_assoc( $result ) ) {
                               $international_cats = stripslashes( $i[ 'categories' ] );
                              $international_display .= <<<PANEL_DISPLAY
<a class="international-tour-box-element" href=# >$international_cats</a>
PANEL_DISPLAY;
                        } //$b = mysql_fetch_assoc( $result )
                } //$result !== false && mysql_num_rows( $result ) > 0
                else {
                         $international_display = <<<PANEL_DISPLAY
<a class="international-tour-box-element" href="#" >No tours !</a>
PANEL_DISPLAY;
                }
                return $international_display;
        }

This my help you:

public function display_international( ) {
                $query = 'SELECT *
      FROM
       tourDB
      WHERE 
        tour_type = "international"';
               $result = mysql_query( $query ) or die( mysql_error() );
                  if ( $result !== false && mysql_num_rows( $result ) > 0 ) {
                       while ( $i = mysql_fetch_assoc( $result ) ) {
                           if (!$i[ 'categories' ]) {
                             continue; // use break; to terminate continue to skip loop
                           }
                               $international_cats = stripslashes( $i[ 'categories' ] );
                              $international_display .= <<<PANEL_DISPLAY
<a class="international-tour-box-element" href=# >$international_cats</a>
PANEL_DISPLAY;
                        } //$b = mysql_fetch_assoc( $result )
                } //$result !== false && mysql_num_rows( $result ) > 0
                else {
                         $international_display = <<<PANEL_DISPLAY
<a class="international-tour-box-element" href="#" >No tours !</a>
PANEL_DISPLAY;
                }
                return $international_display;
        }

Exit the loop:

if ($i['categories'] == '') {
    break;
}

Skip this value in the loop:

while ( $i = mysql_fetch_assoc( $result ) ) {
    if ($i['categories'] != '') {
        // Rest of your code here
    }
}

You can use break to skip the loop or continue to skip the current iteration.

For example

if( $categories == "" ) {
    break; //or continue;
}

You can continue to the next element in the result

if( empty($i[ 'categories' ]) continue;

or break it

if( empty($i[ 'categories' ]) break;

You can use either "break" to break the loop, or "continue" to skip the rest of the loop iteration, and continue with the next one.

Simply do the following to skip the rest of the current iteration.

if($['categories'] == '') continue; 

Alternatively do the following to terminate the loop all together.

if($['categories'] == '') break;