Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Smarty][MySQL][PHP] Rysowanie tabelki (krzyżowej?)
kasior
post
Post #1





Grupa: Zarejestrowani
Postów: 78
Pomógł: 0
Dołączył: 20.12.2005
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Pomózcie proszę, bo juz sie zakręciłem zupełnie. Mam dane, ale z rysowaniem tego juz problem.
Ale po kolei. Są dwie tabele: drivers i graph. W pierwszej sa kierowcy, w drugiej sa zapisywane dane ich statusów w poszczególnym tygodniu (np "w aucie")

Wygląda to tak:

(IMG:http://peterwebs.pl/tabela.jpg)

Jedynki sa wpisane tylko na razie,zeby coś było widać.

Najpierw wyciągam z bazy dane:

  1. $sql= 'select * from drivers where active = "1"';
  2. $stmt = $hDB->prepare($sql);
  3. $stmt->execute();
  4. $num = $stmt->rowCount();
  5.  
  6.  
  7. if ($num>0){
  8. $art = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  9. for ($i=0;$i<$num;$i++){
  10. $art = $stmt->fetch();
  11. $tmpart[] = $art;
  12. $cat_ids[$i] = $tmpart[$i]['driver_id'];
  13.  
  14. }
  15. }
  16.  
  17. foreach ($cat_ids as $cat) {
  18.  
  19. $sql= 'select * from graph where driver = :driver';
  20. $stmt = $hDB->prepare($sql);
  21. $stmt->bindParam(':driver',$cat,PDO::PARAM_INT);
  22. $stmt->execute();
  23. $num = $stmt->rowCount();
  24.  
  25. if ($num>0){
  26. $arty = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  27. for ($i=0;$i<$num;$i++){
  28. $arty = $stmt->fetch();
  29. $arty['note'] = html_entity_decode(stripslashes($arty['note']),ENT_QUOTES,'utf-8');
  30. $tmparty[$arty['driver']][] = $arty;
  31. }
  32.  
  33. }
  34.  
  35. }
  36. $smarty->assign('lsc',$tmpart);
  37. $smarty->assign('plsc',$tmparty);



nastepnie rysuję sobie wiersze i komórki:

  1. <!-- zawartośc tabel -->
  2. <div class="rightd" id="rightd">
  3. {section start=0 step=1 name=tmpart loop=$lsc}
  4. <div style="width:2765px;overflow:hidden;">
  5.  
  6. {assign var=idc value=$lsc[tmpart].drivers_id}
  7.  
  8. {section start=0 step=1 name=arty loop=52}
  9. {if $smarty.section.arty.rownum == $plsc[$idc][arty].week}
  10. <div data-week="{$smarty.section.arty.rownum}" data-driver_id="{$lsc[tmpart].driver_id}" data-driver_name="{$lsc[tmpart].name}" class="cell tips w{$smarty.section.arty.rownum}" id ="w{$smarty.section.arty.rownum}d{$lsc[tmpart].driver_id}" tip="week {$smarty.section.arty.rownum} " onClick="showdial('klasa', '500', this);" >
  11. 1
  12. </div>
  13. {else}
  14. <div data-week="{$smarty.section.arty.rownum}" data-driver_id="{$lsc[tmpart].driver_id}" data-driver_name="{$lsc[tmpart].name}" class="cell tips w{$smarty.section.arty.rownum}" id ="w{$smarty.section.arty.rownum}d{$lsc[tmpart].driver_id}" tip="week {$smarty.section.arty.rownum} " onClick="showdial('klasa', '500', this);" >
  15.  
  16. </div>
  17. {/if}
  18. {/section}
  19.  
  20.  
  21. <div class="clearing"></div>
  22.  
  23. </div>
  24. {/section}
  25. </div>
  26. <div class="clearing"></div>
  27. <!-- end zawartośc tabel -->



N i wiem,że w rysowaniu kkomórek jest zle bo póki co mam puste komórki i ani tak ani siak.
Poprosze o pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kasior
post
Post #2





Grupa: Zarejestrowani
Postów: 78
Pomógł: 0
Dołączył: 20.12.2005
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


ok ok (IMG:style_emoticons/default/smile.gif) Pobrałem dane i mam teraz cos takiego:

  1. (
  2. [7] => Array
  3. (
  4. [0] => Array
  5. (
  6. [graph_id] => 17
  7. [driver] => 7
  8. [week] => 1
  9. [status] => 2
  10. [color] => 91de2d
  11. [note] =>
  12. [truck] => 3
  13. )
  14.  
  15. [1] => Array
  16. (
  17. [graph_id] => 18
  18. [driver] => 7
  19. [week] => 10
  20. [status] => 4
  21. [color] => fff555
  22. [note] =>
  23. [truck] => 3
  24. )
  25.  
  26. [2] => Array
  27. (
  28. [graph_id] => 19
  29. [driver] => 7
  30. [week] => 8
  31. [status] => 2
  32. [color] => 91de2d
  33. [note] =>
  34. [truck] => 0
  35. )
  36.  
  37. )
  38.  
  39. [8] => Array
  40. (
  41. [0] => Array
  42. (
  43. [graph_id] => 20
  44. [driver] => 8
  45. [week] => 7
  46. [status] => 3
  47. [color] => ff4444
  48. [note] =>
  49. [truck] => 0
  50. )
  51.  
  52. [1] => Array
  53. (
  54. [graph_id] => 21
  55. [driver] => 8
  56. [week] => 1
  57. [status] => 3
  58. [color] => ff4444
  59. [note] =>
  60. [truck] => 0
  61. )
  62.  
  63. )
  64.  
  65. )


wyświetlam:

  1. <!-- zawartośc tabel -->
  2. <div class="rightd" id="rightd">
  3. {section start=0 step=1 name=tmpart loop=$lsc}
  4. <div style="width:2765px;overflow:hidden;">
  5.  
  6. {assign var=idc value=$lsc[tmpart].driver_id}
  7.  
  8. {section start=0 step=1 name=arty loop=$plsc[$idc]}
  9.  
  10.  
  11. <div data-week="{$smarty.section.arty.rownum}" data-driver_id="{$lsc[tmpart].driver_id}" data-driver_name="{$lsc[tmpart].name}" class="cell tips w{$smarty.section.arty.rownum}" id ="w{$smarty.section.arty.rownum}d{$lsc[tmpart].driver_id}" tip="week {$smarty.section.arty.rownum} " onClick="showdial('klasa', '500', this);" >
  12. {$plsc[$idc][arty].week}
  13. </div>
  14. {sectionelse}
  15.  
  16. {/section}
  17.  
  18.  
  19. <div class="clearing"></div>
  20.  
  21. </div>
  22. {/section}
  23. </div>
  24. <div class="clearing"></div>
  25. <!-- end zawartośc tabel -->
  26.  



i mam:

(IMG:http://peterwebs.pl/tabela2.jpg)

Niby ok, ale co tu dopisac w wyświetlaniu, zeby puste komórki pokazało jak nie ma danych (IMG:style_emoticons/default/questionmark.gif)

mogę zronbić srodkowa pętle tak:

  1. {section start=0 step=1 name=arty loop=52}
  2.  
  3.  
  4. <div data-week="{$smarty.section.arty.rownum}" data-driver_id="{$lsc[tmpart].driver_id}" data-driver_name="{$lsc[tmpart].name}" class="cell tips w{$smarty.section.arty.rownum}" id ="w{$smarty.section.arty.rownum}d{$lsc[tmpart].driver_id}" tip="week {$smarty.section.arty.rownum} " onClick="showdial('klasa', '500', this);" >
  5. {if $plsc[$idc][arty].week}{$plsc[$idc][arty].week}{else}-{/if}
  6. </div>
  7. {sectionelse}
  8.  
  9. {/section}


i wynik:
(IMG:http://peterwebs.pl/tabela3.jpg)

ale ciągle nie wskakuja komórki na swoje miejsca.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 18:35