hope someone can help me with this little problem. I am trying to echo a tinyint from my MySQL in my backend page to see who accepted and who did not.
this is my code:
<?php
ini_set("display_errors", true);
error_reporting(E_ALL);
global $wpdb;
$result2 = $wpdb->get_results("SELECT * FROM ReparationQuotes ORDER BY Id DESC", OBJECT);
?>
<?php foreach ($result2 as $q2) {
//$quote2 = $wpdb->get_results("SELECT Accepted FROM ReparationQuotes Where ReparationId = '" . esc_sql($q2->Id) . "'", OBJECT);
if ($q2->Accepted == 1)
$accepted = "true";
elseif ($q2->Accepted == 0)
$accepted = "false";
}
?>
Then I am trying to call the variable in my table
<td class="post-title page-title column title">
<strong> <?php echo $accepted ?> </strong>
</td>
Unluckily this is only placing "false". No where to find True. It seems like it is getting the values wrong from mysql.
If I change 1 to 0 and 0 to 1 everything is "true". What might be the problem here? Thanks all for helping out.
Okay I edited my php which brings out the 0 and 1 where seemed necessary. The tinyint cels which have not been filled in will echo "Geen offerte".
This is my result:
<?php
ini_set("display_errors", true);
error_reporting(E_ALL);
global $wpdb;
$result = $wpdb->get_results("SELECT * FROM Reparation ORDER BY Id DESC", OBJECT);
$result2 = $wpdb->get_results("SELECT * FROM ReparationQuotes ORDER BY ReparationId DESC", OBJECT);
?>
<?php
if(count($result) > 0) {
foreach($result as $rep) {
$quote = $wpdb->get_results("SELECT COUNT(Id) as total FROM ReparationQuotes WHERE ReparationId = '" . esc_sql($rep->Id) . "'", OBJECT);
foreach ($result2 as $q2) {
$quote2 = $wpdb->get_results("SELECT Accepted FROM ReparationQuotes Where ReparationId = '" . esc_sql($rep->Id) ."'", OBJECT);
}
?>
and then to output the file like this:
<td class="post-title page-title column title">
<strong><?php if ($quote2) : ?>
<?php echo $quote2[0]->Accepted; ?>
<?php else: ?>
<p style="background-color: gray;">Geen offerte</p>
<?php endif; ?> </strong>
</td>
I opened another question for edits in this code, because not everything seemed to work the way I want it to, but atleast this does the trick until then.