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:
$tableheight = "1200";
$globalconfig = "No";
$csvmanagerid = "1";
$csvFile = "./db/fajnadb.csv";
$firstlineislabels = "Yes";
$columnstoinclude = "1,3,4,5,6,7,8,9";
$columnlabels = "";
$def_sort_by = "3";
$def_sort_by = trim($def_sort_by); $def_sort_order = "Ascending";
$def_sort_order = trim($def_sort_order); $separator = "char(380)";
$step = "15";
$view_link = "No";
$view_url = "";
$edit_link = "No";
$edit_url = "";
$delete_link = "No";
$delete_url = "";
$parse_as_link = "9";
$parse_as_email = "";
$parse_as_img = "1";
$img_max_dim = "";
$image_path_prefix = "./../db/images/";
$image_tn = "./../db/images/tn";
...
if (trim($columnstoinclude) != "") { $columns = explode(",",$columnstoinclude); for ($i = 0; $i < count($columns); $i++){ $columns[$i] = trim($columns[$i]); }
}
if (trim($parse_as_link) != "") { $parse_as_link_columns = explode(",",$parse_as_link); for ($i = 0; $i < count($parse_as_link_columns); $i++){ $parse_as_link_columns[$i] = trim($parse_as_link_columns[$i]); }
}
if (trim($parse_as_email) != "") { $parse_as_email_columns = explode(",",$parse_as_email); for ($i = 0; $i < count($parse_as_email_columns); $i++){ $parse_as_email_columns[$i] = trim($parse_as_email_columns[$i]); }
}
if (trim($parse_as_img) != "") { $parse_as_image_columns = explode(",",$parse_as_img); for ($i = 0; $i < count($parse_as_image_columns); $i++){ $parse_as_image_columns[$i] = trim($parse_as_image_columns[$i]); }
}
if (trim($columnlabels) != "") { $column_labels = explode(",",$columnlabels); for ($i = 0; $i < count($column_labels); $i++) {
$columnlabels1[$i] = trim($column_labels[$i]); }
}
if($globalconfig == 'Yes'){
include 'csvmanager_includes/create_config.php';
}
$display = '<div id="display_table" style="overflow:auto; width:100%; height:'.$tableheight.'px">';
$display .= '<table width="100%" cellpadding="3" cellspacing="1" class="csv_table" id="Table0">
<tr>
<td align="center" valign="middle" class="csv_footer">'.$filenotfoundlabel.'</td>
</tr>
</table>
</div>
';
}
$file = fopen($csvFile, 'r');
if($firstlineislabels == "Yes"){
$label_data = fgets($file); // Get the first line $labels_row++;
if(trim($columnstoinclude) != ""){ for ($i = 0; $i<count($labels1); $i++){
if(count($columnlabels1) > 0
){ }
else{
$labels[array_search($i, $columns)] = trim($labels1[$i]); // Creates an array starting from 0 that contains only the usefull labels }
}
}
}
else{ // If no user input exists as far as column selection is concerned, labels = labels1 (all labels)
$labels = $labels1;
for ($i = 0; $i < count($labels1); $i++){ $columns[$i] = $i;
}
}
}
// -------------------------------------------------------- If no labels row exists, retrieve the number of columns in the file
else{
// See how many columns the file has
$columns_data = fgets($file); // Get the first line $columns_number = explode($separator, trim($columns_data)); // explode it to see how many columns fclose($file); // close the file and then open it again so it is ready for from the start $file = fopen($csvFile, 'r'); for($i = 0; $i < count($columnlabels1); $i++){ // IF user column selection exist, the previously seen array $keys is identical with $columns }
}
else{ // Else take into consideration ALL columns
for ($k = 0; $k < count($columns_number); $k++){ $columns[$k] = $k;
$labels[$k] = $k; // In which case also $columns and $lables1 AND $labels are equal
}
}
}
if (count($labels) != count($columns)) { // Perform a check, the columns array and the labels array MUST have the same count. 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."); }
// Read the entire file to get the records
$k = 0;
unset($data, $data_array); for($i = 0; $i < count($data_array); $i++){ // Lets check if it has to be parsed as email, URL or image
if(in_array($i, $parse_as_email_columns) and
trim($data_array[$i]) != ""){ $values[$labels[array_search($i, $columns)]][] = '<a href="mailto:'.$data_array[$i].'" class="csv_link">'.$data_array[$i].'</a>'; $echo = '<a href="mailto:'.$data_array[$i].'" class="csv_link">'.$data_array[$i].'</a>';
}
else if(in_array($i, $parse_as_link_columns) and
trim($data_array[$i]) == "1"){ $values[$labels[array_search($i, $columns)]][] = '<a href="./torba.php" target="_parent"><img src="./images/add.png" title="Kliknij aby dodać do torby"></a>'; }
else if(in_array($i, $parse_as_link_columns) and
trim($data_array[$i]) == "0"){ $values[$labels[array_search($i, $columns)]][] = '<img src="./images/reserved.png" title="Rezerwacja!">'; }
else if(in_array($i, $parse_as_image_columns) and
trim($data_array[$i]) != ""){ $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>'; }
else{
}
if ($echo) {
//echo $echo."<br>";
}
}
}
konkretnie chodzi mi o wycinek:
else if(in_array($i, $parse_as_link_columns) and
trim($data_array[$i]) == "1"){ $values[$labels[array_search($i, $columns)]][] = '<a href="./torba.php" target="_parent"><img src="./images/add.png" title="Kliknij aby dodać do torby"></a>'; }
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..?
Ten post edytował shpaque 10.07.2011, 13:49:35