Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

True or False on Loop

I am able to print all values from a table but I would just like to learn how to print next to it when it matches the value from the URL variable &year=

$setYear = $_GET['year'];
print $setYear . "<br><br>";
$Success = "YES";

while ($row = $resultselect->fetch_assoc()) {

   echo $row["Orders_Year"] . " <br>";
   // Should I do a for loop?

}

Should I do for a loop to evaluate each record? I have been trying different things to learn but I seem to be stuck learning this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming the date fields are the same format all you need is a simple test to see if the dates are the same

$Success = 'YES';

while ($row = $resultselect->fetch_assoc()) {

    echo $row['Orders_Year'];
    if ( $_GET['year'] == $row['Orders_Year'] ) {
        echo ' ' . $Success;
    }
    echo '<br>';
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading