对笨拙的问题感到抱歉,我不确定这是否可行,我使用 json 从 Mysql db 中正确读取数据并将它们显示到数据库中不是表的元素中我有一些约会日期将按周显示给客户组并有下一个链接到其他周。有一些代码,我很抱歉很多。这是html代码:
<div class="timesviewport">
<div class="selector">
<div class="title-collection" style="">
<!--time add here-->
</div>
<div class="selector-header">
<div class="header-title-collection" style="">
<!--date add here-->
</div>
<div class="control">
<div class="prevlink">
<div class="nextprevloading"></div>
<a class="prevweeklink" href="#" rel="nofollow">before</a>
</div>
<div class="nextlink">
<div class="nextprevloading"></div>
<a class="nextweeklink" href="#" rel="nofollow" data-test="search-next-week-link">next</a>
</div>
</div>
</div>
</div>
</div>
这是javascript
function getresDetails(id)
{
var new_res_date = '' ;
var new_res_time = '' ;
new_res_time += '<div class="title"><div class="title-row-collection">';
daily = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
j=0;
var id_val = id.value;
var url = "table.php?id="+id_val;
$.getJSON(url, function(json) {
new_res_date +='<div class="header-title"><div class="header-title-date-collection" id="adddate">';
new_res_time += '<div class="title-row"><div class="title-row-date-collection">' ;
$.each(json, function(i, value) {
if(i==0)
{
new_res_date += '<div class="header-title-date"><div class="header-title-date-name">'+daily[j%7]+ '</div><div class="header-title-date-value">'+json[i].res_date+ '</div></div>';
new_res_time += '<div class="title-row-date"><div class="appointment-collection"><div class="appointment-collection-first"><div><a class="appointment-time" href="#">'+json[i].res_time+'</a></div>' ;
//alert("first :" +i);
j++;
}
else if (i>0 && json[i-1].res_date==json[i].res_date)
{
new_res_time += '<div><a class="appointment-time" href="#">'+json[i].res_time+ '</a></div>';
//alert("second :" +i);
}
else
{
new_res_date += '<div class="header-title-date"><div class="header-title-date-name">'+daily[j%7]+ '</div><div class="header-title-date-value">'+json[i].res_date+ '</div></div>';
new_res_time += '</div></div></div><div class="title-row-date"><div class="appointment-collection"><div class="appointment-collection-first"><div><a class="appointment-time" href="#">'+json[i].res_time+ '</a></div>';
//alert("third :" +i);
j++;
}
});
j=0;
new_res_date += '</div></div>' ;
new_res_time += '</div></div></div></div></div></div></div>' ;
$(new_res_time).appendTo(".title-row-collection");
$(new_res_date).appendTo(".header-title-collection");
});
}
和其他从数据库读取数据的页面在这里
table.php
:
<?php
include 'configure.php';
$doc_id = $_GET["id"];
$qr = "SELECT `res_date`,`res_time` FROM `reserve_tbl` WHERE `doc_id` = '".$doc_id."'";
$res= mysql_query($qr);
$i=0;
while($row = mysql_fetch_array($res))
{
$res_arr[$i]["res_date"] = $row["res_date"];
$res_arr[$i]["res_time"] = $row["res_time"];
$i++;
}
header('Content-type: application/json');
echo json_encode($res_arr);
?>
和
profinf.php
:
<?php
include 'configure.php';
$doc_id = $_GET["id"];
$qr = "SELECT * FROM `doc_tbl` WHERE `doc_id` = '".$doc_id."'";
$res= mysql_query($qr) or die("Error: " . mysql_error() . "<br />In Query: " . $qr);;
$i=0;
while($row = mysql_fetch_array($res))
{
$doc_arr[$i]["doc_name"] = $row["doc_name"];
$doc_arr[$i]["doc_family"] = $row["doc_family"];
$doc_arr[$i]["doc_grade"] = $row["doc_grade"];
$doc_arr[$i]["doc_specialy"]= $row["doc_specialy"];
$doc_arr[$i]["doc_adress"] = $row["doc_adress"];
$i++;
}
header('Content-type: application/json');
echo json_encode($doc_arr);
?>
最后这里是连接configure.php
<?php
$cfg_server = "localhost";
$cfg_database = "db_name";
$cfg_username = "root";
$cfg_password = "";
$conn = mysql_connect($cfg_server, $cfg_username, $cfg_password);
if($conn)
{
if (!mysql_select_db($cfg_database))
{
die('Could not select Database: '.mysql_error());
}
}
if (!$conn)
{
die('Could not connect to Database: '.mysql_error());
}
?>
以前有人有同样的问题吗?我需要按不是表格的每周元素显示日期列组,如果我使用表格更容易?但我不知道如何在表中显示列每周组!我可以通过 SQL 查询按数据分组吗?
谢谢。