I have 12 different id’s I want to compare to $_GET. Right now I’m pulling all my id’s like this:
$sth = $dbh->query('SELECT DISTINCT courseId from training');
$sth->setFetchMode(PDO::FETCH_ASSOC);
while($row = $sth->fetch('courseId')) {
print_r($row['courseId'] . ',');
}
This returns:
8,5,9,10,12,7,4,3,2,6,11,1,
Now, I want to check the id’s against $_GET['courseId']
How do I write an if statement to compare the values of $row['courseId'] and $_GET['courseId']. I want to do something like:
if($_GET['courseId'] == $row['1']) {
//Do something here
} elseif ($_GET['courseId'] == $row['2']) {
//Do something different
}
Hopefully that makes sense. Thanks!
Replace your
print_rline with:Then, after the loop: