2013-01-22 79 views
2

遺憾笨拙質疑, 我真的不知道它有可能,我從MySQL使用JSON 分貝正確讀取數據,並顯示爲元素,是不是表 在數據庫中,我有一些預約日期將按周顯示給客戶組,並且每週有下一個鏈接。 有一些代碼,我很抱歉。 這裏是HTML代碼:頁眉每週按日期列JSON

<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"); 
    }); 
} 

,並從DATABSE讀取數據的其他頁面在這裏

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); 
?> 

finaly這裏是連接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查詢數據分組?

謝謝。

+0

真的沒有人? –

+0

我不確定我是否理解你需要每週查看一些數據? – We0

+0

_「真的沒人?!」_ - TL; DR也許? – CBroe

回答

1

mySql有一個星期功能。

如果你改變你的查詢

: -

SELECT `res_date`,`res_time`, WEEK(res_date) AS `res_week` FROM `reserve_tbl` WHERE `doc_id` = '".$doc_id."'"; 

你將能夠使用res_week場,以跟蹤數週每一條記錄,並因此表現出一個和下一個星期