下面的代码将回显yes,no,may或来自db的文本。我希望输出在这样的表中
echo "<tr><td><b>OUTPUT HERE</b></td></tr>";
这是完整的代码。
<?php
global $wpdb;
$current_user = wp_get_current_user();
$result = $wpdb->get_results( "
SELECT stats.*
FROM wp_wp_pro_quiz_statistic stats
JOIN wp_wp_pro_quiz_statistic_ref refs on stats.statistic_ref_id = refs.statistic_ref_id
WHERE refs.user_id= $current_user->ID && refs.quiz_id= 5");
foreach($result as $row) {
echo "<tr><td><b></b></td></tr>";
$a = $row->answer_data;
$b = json_decode($a, true);
if($b[0] == 1){ echo 'Yes'; }
if($b[1] == 1){ echo 'No'; }
if($b[2] == 1){ echo 'Maybe'; }
if(count($b) == 1){ echo '$row->answer_data'; }
}
?>
我希望有人可以帮助并感谢你
答案 0 :(得分:0)
您可以回显开始标记,然后是内容,关闭它们。
<?php
echo "<tr><td><b>";
// Echo query results
echo "</b></td></tr>";
答案 1 :(得分:0)
你可以这样做:
foreach($result as $row) {
if(count($b) == 1){//maybe > 0 ?
echo "<tr><td><b>";
$a = $row->answer_data;
$b = json_decode($a, true);
if($b[0] == 1){ echo 'Yes'; }
if($b[1] == 1){ echo 'No'; }
if($b[2] == 1){ echo 'Maybe'; }
echo $row->answer_data;
echo "</b></td></tr>";
}
}
答案 2 :(得分:0)
试试这个:它会起作用。
<?php
global $wpdb;
$current_user = wp_get_current_user();
$result = $wpdb->get_results( "
SELECT stats.* FROM wp_wp_pro_quiz_statistic stats JOIN wp_wp_pro_quiz_statistic_ref refs on stats.statistic_ref_id = refs.statistic_ref_id WHERE refs.user_id= $current_user->ID && refs.quiz_id= 5");
foreach($result as $row) {
$a = $row->answer_data;
$b = json_decode($a, true);
$myOutput;
if($b[0] == 1){ $myOutput = 'Yes'; }
if($b[1] == 1){ $myOutput = 'No'; }
if($b[2] == 1){ $myOutput = 'Maybe'; }
if(count($b) == 1){
echo "<tr><td><b>".$myOutput."</b></td></tr>";
}
}
?>