I feel like this is probably an easy one but just can't see it!
I've built a test where results are saved into a database table. At the moment it's saving a row for every test taken. The test can be taken until it's passed.
At the moment it's outputting every result (as it's looping over every result in the table).
How can I only output $row['testname'];
once if the output of $row['pass-fail'];
is "Pass"?
<?php $current_user = wp_get_current_user();
$user = $current_user->user_login;
require("database.php");
// Opens a connection to a MySQL server
$con = mysql_connect("localhost", $username, $password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tester", $con);
$sql = mysql_query("SELECT * FROM test WHERE name='$user' ORDER BY Date DESC");
if (!$sql) {
die('Error: ' . mysql_error());
} ?>
<?php while($row = mysql_fetch_array($sql)) { ?>
<p><?php $testname = $row['testname']; echo get_the_title( $testname ); ?> - <?php echo $row['pass-fail']; ?></p>
<?php } ?>
<?php mysql_close($con); ?>