How to stop loop in while statement in PHP MySQL?
<p>I would like to ask. </p>

<p>Is it okay to add <strong>exit();</strong> at the end of each statement or is there any good way besides <strong>exit();</strong> ? </p>

<p>The reason is stop the display data from looping, <strong>Because if I remove/disable exit();</strong>, the data will loop and display all the row available in database table. And else statement will also execute if the exit(); remove from the code.</p>

<p>The code as below : </p>

<pre><code>&lt;?php
    $connect      = mysqli_connect("localhost", "root", "", "database");
    global $connect;   

    if(isset($_POST['Submit'])){
        $input       = $_POST['input'];

        $sql = "SELECT * FROM table";
        $get = mysqli_query($connect,$sql);
        if($get &amp;&amp; mysqli_num_rows($get) &gt; 0 ){ 
            while($row = mysqli_fetch_assoc($get)){
                $input_db  = $row['input'];
                $output_db = $row['output'];

                if (($input &gt;= $input_db) &amp;&amp; ($output &lt;= $output_db))
                {
                    echo "Input and output is in between";
                    exit();
                }
                else
                {
                    echo "Data added ! &lt;br/&gt;";
                    exit();
                }
            }
        mysqli_free_result($get);   
        }
        else
        {
            echo "data is outside range";
        }
    }
?&gt;
&lt;form action="testdate.php" method="post"&gt;  
    &lt;table&gt; 
        &lt;tr&gt;
            &lt;td&gt;&lt;i class="fa fa-unlock-alt"&gt;&lt;/i&gt; &lt;/td&gt;
            &lt;td&gt;Input : &lt;/td&gt;
            &lt;td&gt;&lt;input type ="text" name="input" size="30"&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;    

    &lt;p&gt;&lt;input class="btnSuccess" type ="submit" name="Submit" value="Submit"&gt; &lt;/p&gt;              
&lt;/form&gt;
</code></pre>

<p>Thanks.</p>