omarf Posted October 21, 2008 Share Posted October 21, 2008 I'm using DaDaBIK as the front end for a mySQL database and I need some help setting a table layout. The details of a record page currently looks like this: Field1 Value1 Field2 Value2 Field3 Value3 Field4 Value4 ...etc I wish to style it like this Field1 Value1 | Field2 Value2 Field3 Value3 | Field4 Value4 ...etc Below is the part of the php file that controls the output of this page: function build_details_table($fields_labels_ar, $res_details) // goal: build an html table with details of a record // input: $fields_labels_ar $res_details (the result of the query) // ouptut: $details_table, the html table { global $conn, $quote, $alias_prefix, $prefix_internal_table; // build the table $details_table = ""; $details_table .= "<table>"; while ($details_row = fetch_row_db($res_details)){ // should be just one $count_temp = count($fields_labels_ar); for ($i=0; $i<$count_temp; $i++){ if ($fields_labels_ar[$i]["present_details_form_field"] == "1"){ $field_name_temp = $fields_labels_ar[$i]["name_field"]; // hack for mssql, an empty varchar ('') is returned as ' ' by the driver, see http://bugs.php.net/bug.php?id=26315 // could be not set if it's a foreign key if (isset($details_row[$field_name_temp]) && $details_row[$field_name_temp] === ' ') { $details_row[$field_name_temp] = ''; } // end if $field_values_ar = array(); // reset the array containing values to display, otherwise for each loop if I don't call build_linked_field_values_ar I have the previous values $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"]; if ($primary_key_field_field != ""){ $primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"]; $primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"]; $primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"]; $linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"]; $linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field); $alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"]; // get the list of all the installed tables $tables_names_ar = build_tables_names_array(0); // if the linked table is installed I can get type content and separator of the linked field if (in_array($primary_key_table_field, $tables_names_ar)) { $linked_table_installed = 1; $fields_labels_linked_field_ar = build_fields_labels_array($prefix_internal_table.$primary_key_table_field, "1"); } // end if else { $linked_table_installed = 0; } // end else for ($j=0;$j<count($linked_fields_ar);$j++) { ////*$field_values_ar[$j] = $details_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field]; $field_values_ar[$j] = $details_row[$primary_key_table_field.$alias_prefix.$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field]; } // end for /* $linked_field_values_ar = build_linked_field_values_ar($details_row[$field_name_temp], $primary_key_field_field, $primary_key_table_field, $primary_key_db_field, $linked_fields_ar); */ /* if (substr($foreign_key_temp, 0, 4) == "SQL:"){ $sql = substr($foreign_key_temp, 4, strlen($foreign_key_temp)-4); } // end if else{ */ //$field_values_ar = $linked_field_values_ar; } else{ $field_values_ar[0] = $details_row[$field_name_temp]; } $count_temp_2 = count($field_values_ar); $details_table .= "<tr><td class=\"td_label_details\"><b>".$fields_labels_ar[$i]["label_field"]."</b></td><td class=\"td_value_details\">"; for ($j=0; $j<$count_temp_2; $j++) { // if it's a linked field and the linked table is installed, get the correct $field_type $field_content $field_separator if ($primary_key_field_field != "" && $primary_key_field_field != NULL && $linked_table_installed === 1){ foreach ($fields_labels_linked_field_ar as $fields_labels_linked_field_ar_element){ if ($fields_labels_linked_field_ar_element['name_field'] === $linked_fields_ar[$j]) { $linked_field_type = $fields_labels_linked_field_ar_element['type_field']; $linked_field_content = $fields_labels_linked_field_ar_element['content_field']; $linked_field_separator = $fields_labels_linked_field_ar_element['separator_field']; } // end if } // end foreach reset($fields_labels_linked_field_ar); $field_to_display = get_field_correct_displaying($field_values_ar[$j], $linked_field_type, $linked_field_content, $linked_field_separator, "details_table"); // get the correct display mode for the field } // end if else { $field_to_display = get_field_correct_displaying($field_values_ar[$j], $fields_labels_ar[$i]["type_field"], $fields_labels_ar[$i]["content_field"], $fields_labels_ar[$i]["separator_field"], "details_table"); // get the correct display mode for the field } // end else $details_table .= $field_to_display." "; // at the field value to the table } $details_table = substr($details_table, 0, -6); // delete the last $details_table .= "</td></tr>"; //$field_to_display = get_field_correct_displaying($details_row[$field_name_temp], $fields_labels_ar[$i]["type_field"], $fields_labels_ar[$i]["content_field"], $fields_labels_ar[$i]["separator_field"], "details_table"); // get the correct display mode for the field //$details_table .= "<tr><td class=\"td_label_details\"><b>".$fields_labels_ar[$i]["label_field"]."</b></td><td class=\"td_value_details\">".$field_to_display."</td></tr>"; } // end if } // end for } // end while $details_table .= "</table>"; return $details_table; } // end function build_details_table And here is the current CSS code for the tags on this page: /********* DETAIL PAGE ********* */ /* the cell that contains the label */ .td_label_details{ text-align: right; vertical-align: top; } /* the cell that contains the value */ .td_value_details{ vertical-align: top; } I've attached the full php file as well as the complete css file. To see this in action: http://www.smofco.com/dada . I'm a PHP newbie and learning as I go, so thanks for any input! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/129334-solved-help-with-table-layout/ Share on other sites More sharing options...
omarf Posted October 22, 2008 Author Share Posted October 22, 2008 Never mind, solved with an odd/even checking loop. if($i % 2) { $details_table .= "<tr><td class=\"td_label_details\"><b>".$fields_labels_ar[$i]["label_field"]."</b></td><td class=\"td_value_details\">"; } else { $details_table .= "<td class=\"td_label_details\"><b>".$fields_labels_ar[$i]["label_field"]."</b></td><td class=\"td_value_details\">"; } // end else Link to comment https://forums.phpfreaks.com/topic/129334-solved-help-with-table-layout/#findComment-672067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.