[英]SQL query html table format
How to echo the left column table to "Daily" "Monthly" and "Yearly"?如何将左列表呼应为“每日”“每月”和“每年”? It currently displays repeatedly because the results of SQL queries on the right side are 3 items.
目前重复显示是因为右侧SQL查询结果为3项。
$ID = get_current_user_id();
global $wpdb;
if(isset($_GET["view_data"])){
$SubmissionID = $_GET["view_data"];
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}myTable WHERE user_id = {$ID} AND `key` IN ('name1', 'name2', 'name3')", OBJECT );
if(isset($_GET["form_name"])) echo "<h4>YOUR REVIEW ON {$_GET["form_name"]}</h4>";
echo "<table>";
foreach ($results as $result) {
echo "<tr>";
echo "<td>";
echo "<p>test1</p>";
echo "</td>";
echo "<td>";
echo $result->value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<h4><a href='?view_all'>Back to List</a></h4>";
}
The current output of my code:我代码的当前output:
test1![]() |
dynamic_data_1![]() |
---|---|
test1![]() |
dynamic_data_2![]() |
test1![]() |
dynamic_data_3![]() |
The output I need:我需要的output:
Daily![]() |
dynamic_data_1![]() |
---|---|
Monthly![]() |
dynamic_data_2![]() |
Yearly![]() |
dynamic_data_3![]() |
add a counter:添加一个计数器:
$ID = get_current_user_id();
global $wpdb;
if(isset($_GET["view_data"])){
$SubmissionID = $_GET["view_data"];
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}myTable WHERE user_id = {$ID} AND `key` IN ('name1', 'name2', 'name3')", OBJECT );
if(isset($_GET["form_name"])) echo "<h4>YOUR REVIEW ON {$_GET["form_name"]}</h4>";
$count = 0;
echo "<table>";
foreach ($results as $result) {
$count++;
$title = 'DEFAULT Title';
if( $count == 1 ){
$title = 'Daily';
}
elseif( $count == 2 ){
$title = 'Monthly';
}
elseif( $count == 3 ){
$title = 'Yearly';
}
echo "<tr>";
echo "<td>";
echo "<p>" . $title ."</p>";
echo "</td>";
echo "<td>";
echo $result->value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<h4><a href='?view_all'>Back to List</a></h4>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.