Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Sesja i Rekordy z 3 plików
Forum PHP.pl > Forum > PHP
shpaque
Witam serdecznie - dziś mam jak dla mnie ogromny problem z rozwikłaniem kodu i dojściem do skutku - już mnie coś trafia (trzeba było jednak iść na informatykę)

Ale o co chodzi? Wrzuciłem skrypt Technosystems; mam powiedzmy sobie sklep, w którym są 3 kategorie towaru - każda z nich korzysta z oddzielnego pliku csv. Tabelka z rekordami wygląda następująco:

  1. $tableheight = "1200";
  2. $globalconfig = "No";
  3. $csvmanagerid = "1";
  4. $csvFile = "./db/fajnadb.csv";
  5. $firstlineislabels = "Yes";
  6. $columnstoinclude = "1,3,4,5,6,7,8,9";
  7. $columnlabels = "";
  8. $def_sort_by = "3";
  9. $def_sort_by = trim($def_sort_by);
  10. $def_sort_order = "Ascending";
  11. $def_sort_order = trim($def_sort_order);
  12. $separator = "char(380)";
  13. $step = "15";
  14. $view_link = "No";
  15. $view_url = "";
  16. $edit_link = "No";
  17. $edit_url = "";
  18. $delete_link = "No";
  19. $delete_url = "";
  20.  
  21. $parse_as_link = "9";
  22. $parse_as_email = "";
  23. $parse_as_img = "1";
  24. $img_max_dim = "";
  25. $image_path_prefix = "./../db/images/";
  26. $image_tn = "./../db/images/tn";
  27.  
  28. ...
  29.  
  30.  
  31. if (trim($columnstoinclude) != "") {
  32. $columns = explode(",",$columnstoinclude);
  33. for ($i = 0; $i < count($columns); $i++){
  34. $columns[$i] = trim($columns[$i]);
  35. }
  36. }
  37.  
  38. if (trim($parse_as_link) != "") {
  39. $parse_as_link_columns = explode(",",$parse_as_link);
  40. for ($i = 0; $i < count($parse_as_link_columns); $i++){
  41. $parse_as_link_columns[$i] = trim($parse_as_link_columns[$i]);
  42. }
  43. }
  44.  
  45. if (trim($parse_as_email) != "") {
  46. $parse_as_email_columns = explode(",",$parse_as_email);
  47. for ($i = 0; $i < count($parse_as_email_columns); $i++){
  48. $parse_as_email_columns[$i] = trim($parse_as_email_columns[$i]);
  49. }
  50. }
  51.  
  52. if (trim($parse_as_img) != "") {
  53. $parse_as_image_columns = explode(",",$parse_as_img);
  54. for ($i = 0; $i < count($parse_as_image_columns); $i++){
  55. $parse_as_image_columns[$i] = trim($parse_as_image_columns[$i]);
  56. }
  57. }
  58.  
  59. if (trim($columnlabels) != "") {
  60. $column_labels = explode(",",$columnlabels);
  61. for ($i = 0; $i < count($column_labels); $i++)
  62. {
  63. $columnlabels1[$i] = trim($column_labels[$i]);
  64. }
  65. }
  66.  
  67. if($globalconfig == 'Yes'){
  68. include 'csvmanager_includes/create_config.php';
  69. }
  70.  
  71. if(!file_exists($csvFile)){
  72. $display = '<div id="display_table" style="overflow:auto; width:100%; height:'.$tableheight.'px">';
  73. $display .= '<table width="100%" cellpadding="3" cellspacing="1" class="csv_table" id="Table0">
  74. <tr>
  75. <td align="center" valign="middle" class="csv_footer">'.$filenotfoundlabel.'</td>
  76. </tr>
  77. </table>
  78. </div>
  79. ';
  80. echo $display;
  81. }
  82.  
  83. if(file_exists($csvFile) and filesize($csvFile) > 0){
  84. $file = fopen($csvFile, 'r');
  85.  
  86. if($firstlineislabels == "Yes"){
  87. $label_data = fgets($file); // Get the first line
  88. $labels_row++;
  89. $labels1 = explode($separator, trim($label_data));
  90. if(trim($columnstoinclude) != ""){
  91. for ($i = 0; $i<count($labels1); $i++){
  92. if(in_array($i, $columns)){
  93. if(count($columnlabels1) > 0){
  94. $labels[array_search($i, $columns)] = trim($columnlabels1[array_search($i,$columns)]);
  95. }
  96. else{
  97. $labels[array_search($i, $columns)] = trim($labels1[$i]); // Creates an array starting from 0 that contains only the usefull labels
  98. }
  99. }
  100. }
  101.  
  102. }
  103. else{ // If no user input exists as far as column selection is concerned, labels = labels1 (all labels)
  104. $labels = $labels1;
  105. for ($i = 0; $i < count($labels1); $i++){
  106. $columns[$i] = $i;
  107. }
  108. }
  109. }
  110.  
  111. // -------------------------------------------------------- If no labels row exists, retrieve the number of columns in the file
  112. else{
  113. // See how many columns the file has
  114. $columns_data = fgets($file); // Get the first line
  115. $columns_number = explode($separator, trim($columns_data)); // explode it to see how many columns
  116. fclose($file); // close the file and then open it again so it is ready for from the start
  117. $file = fopen($csvFile, 'r');
  118. if(count($columnlabels1) > 0 and count($columns) > 0 and count($columnlabels1) == count($columns)){
  119. for($i = 0; $i < count($columnlabels1); $i++){ // IF user column selection exist, the previously seen array $keys is identical with $columns
  120. $labels[array_search($i,$columns)] = $columnlabels1[array_search($i,$columns)];
  121. }
  122. }
  123. else{ // Else take into consideration ALL columns
  124. for ($k = 0; $k < count($columns_number); $k++){
  125. $columns[$k] = $k;
  126. $labels[$k] = $k; // In which case also $columns and $lables1 AND $labels are equal
  127. }
  128. }
  129. }
  130.  
  131. if (count($labels) != count($columns)) { // Perform a check, the columns array and the labels array MUST have the same count.
  132. die("Column number doesn't match Labels number. I can't set correctly the column headers. Please review your settings. The number of Columns to include and the number of column labels should be the same.");
  133. }
  134.  
  135. // Read the entire file to get the records
  136. $k = 0;
  137. while (!feof($file)){
  138. unset($data, $data_array);
  139. $data = trim(fgets($file));
  140. $data_array = explode($separator, trim($data));
  141. for($i = 0; $i < count($data_array); $i++){
  142. if (in_array($i, $columns)) {
  143. unset($echo);
  144. // Lets check if it has to be parsed as email, URL or image
  145. if(in_array($i, $parse_as_email_columns) and trim($data_array[$i]) != ""){
  146. $values[$labels[array_search($i, $columns)]][] = '<a href="mailto:'.$data_array[$i].'" class="csv_link">'.$data_array[$i].'</a>';
  147. $echo = '<a href="mailto:'.$data_array[$i].'" class="csv_link">'.$data_array[$i].'</a>';
  148. }
  149. else if(in_array($i, $parse_as_link_columns) and trim($data_array[$i]) == "1"){
  150. $values[$labels[array_search($i, $columns)]][] = '<a href="./torba.php" target="_parent"><img src="./images/add.png" title="Kliknij aby dodać do torby"></a>';
  151. }
  152. else if(in_array($i, $parse_as_link_columns) and trim($data_array[$i]) == "0"){
  153. $values[$labels[array_search($i, $columns)]][] = '<img src="./images/reserved.png" title="Rezerwacja!">';
  154. }
  155. else if(in_array($i, $parse_as_image_columns) and trim($data_array[$i]) != ""){
  156. $values[$labels[array_search($i, $columns)]][] = '<a href= "'.$image_path_prefix.$data_array[$i].'"><img src="'.$image_tn.$data_array[$i].'" title="Zobacz większe zdjęcie"></a>';
  157. }
  158. else{
  159. $values[$labels[array_search($i, $columns)]][] = stripslashes($data_array[$i]);
  160. }
  161. if ($echo) {
  162. //echo $echo."<br>";
  163. }
  164.  
  165. }
  166. }



konkretnie chodzi mi o wycinek:


  1. else if(in_array($i, $parse_as_link_columns) and trim($data_array[$i]) == "1"){
  2. $values[$labels[array_search($i, $columns)]][] = '<a href="./torba.php" target="_parent"><img src="./images/add.png" title="Kliknij aby dodać do torby"></a>';
  3. }


Jak zrobić, żeby po kliknięciu w ikonkę (tutaj: "add.png") przechodziło się do "torba.php" ze wszystkimi danymi (rozbitymi na zdjęcie, kod produktu, nazwa, opis - no i w zaleznosci od bazy danych cena) z konkretnego wiersza dodatkowo żeby przeszła informacja z ktorej bazy danych rekord został pobrany?

tzn chce cos takiego:
zeby kierując na stronę 'torba' mogl sobie rozbic informację na składowe (tak jak one są w pliku) i powyciągać interesujące mnie dane do wyświetlenia stanu koszyka czyli:
1 z 3 baz danych| link do miniatury | kod produktu | nazwa | cena (1 z 3 - w zależności od bazy danych)

dodatkowo na koncu transakcji zeby sprawdził czy wartość na koncu wiersza dalej jest "1" i zmienił ją na "0" lub jeśli nagle jest "0" zeby dał komunikat ze dana rzecz zostala wlasnie zarezerwowana..?
CuteOne
Na początek przeczytaj to (na google poszukaj więcej artykułów o odczytywaniu zmiennej $_GET) . Gdy dojdziesz do momentu gdzie tworzenie linków i ich odczyt nie będzie dla Ciebie problemem powinieneś bez problemu poradzić sobie z resztą
shpaque
jednak się udało, dzięki!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.