Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have no idea if this does what you want it to or not, but I think you could benefit from reading the book "Code Complete" by Steve McConnell. Anyone who has to understand this code has to work very, very hard to understand the intent, and the deeply nested logic statements make it hard to see what's going on. </p> <p>Firstly, as @yes123 says, indentation helps. </p> <p>Secondly, comments would be nice. </p> <p>Thirdly, reducing the complexity would really help. For instance, instead of </p> <pre><code>if ( isset( $_POST['code_search_submitted'])) { </code></pre> <p>You might say: if (isValidSearch($_POST)) {</p> <pre><code> } if ( isCodeSearch($_POST)) { </code></pre> <p>and wrap your check for the post var into a separate function. </p> <p>Next, you might wrap the inner body of your IF statements into functions too - for instance, replace if (is_numeric( $_POST['searchText']) &amp;&amp; (strlen($_POST['searchText']) == 4)) {</p> <pre><code> $searchCode = $_POST['searchCode']; if ( $searchCode == 1 ) { $_SESSION['searchCode'] = 'TutorCode'; } elseif ( $searchCode == 2 ) { $_SESSION['searchCode'] = 'InstituteCode'; } $_SESSION['searchText'] = $_POST['searchText']; } </code></pre> <p>with</p> <pre><code>if (isValidSearch($_POST)) { handleSearch($POST) } </code></pre> <p>Next, I'd encourage you to split the business logic in your app from the display logic - wrapping HTML statements inside your business logic (e.g. the Javascript errors) makes it REALLY hard to maintain. Consider an MVC framework. This also applies to separating out the business logic from the application logic (the output buffering for instance) - for a non-trivial application, you want to be able to modify the business logic without worrying about breaking the application logic and vice versa. Your sample code suggests that a simple change in the business logic (e.g. adding a new type of search) could easily lead to someone forgetting to re-set the output buffer...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload