Theres an error - But i dont see it (php)

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
codiemorgan
Registered User
Posts: 15
Joined: 14 Jul 2010, 11:40

Theres an error - But i dont see it (php)

Post by codiemorgan »

I think there is an error in this function somewere:

Code: Select all

// std table  ( for 'lists'.php ) - requires a arraer containing arrays of Fiels/Values and Columns
// contains ( or will contain ) column adding, seletion, field adding, row buttons and 'Add New' row....
// list item MUST at leas have columns/propertie/fields - such as the template provided by fw_list_new();
// ['name'] also required in array
function ui_tablelist($title,$list,$headers_array = null,$row_buttons=array(),$show_add = true){
	ui_panel_start(admin_label($title));
	if(is_array($list)){	
	
		$valid = false;
		if(isset($list[FW_LIST_ITEMS])){  $valid = true ; }
		if(isset($list[FW_LIST_COLUMNS])){  $valid = true ; }
		if($valid) { $valid = is_array($list[FW_LIST_ITEMS]); }
		if($valid) { $valid = is_array($list[FW_LIST_COLUMNS]); }
		
		// Items should match columns, but display based on columns currently availabl
		// [items][[row]][column/p] = <value>

		if(!$valid){
			
			echo '<p>List is Empty</p>';
			if(isset($list[FW_LIST_COLUMNS])){
				?><table class=""><?php
          		_table_add($list[FW_LIST_COLUMNS]); // <-- the option to add a item to this empty list
				?></table><?php
			}
			
		}else{

			if(count($list[FW_LIST_ITEMS]) > 0 ){
				?>
				<div class="">
				<?php 
				// header buttons if any 
				if ( is_array( $headers_array ) ) { foreach ( $headers_array as $name => $label ) {
						?><input name="<?php echo $name ?>" type="submit" value="<?php echo admin_label($name) ?>" /><?php
					}
				}	
				?>
				</div>
				<table>
				<!-- header start -->
				<tr class="">
				<?php
				// headers
				if(is_array($list[FW_LIST_COLUMNS])){ foreach($list[FW_LIST_COLUMNS] as $columnheader ) {
						?><td class=""><?php echo admin_label($columnheader); ?></td><?php	
				} }
				?>
				</tr>
				<!-- header end -->
				<!-- rows start -->
				<?php 
				if( is_array($list[FW_LIST_ITEMS] )){ foreach($list[FW_LIST_ITEMS	] as $rowID => $item_row) {
						// $item row must be $p/column => $v	
						?>
						<tr class="">
                            <!-- items -->
                            <?php
                            // checking by available columns, not by available peroperties in each row
                            foreach( $list[FW_LIST_COLUMNS] as $column ){
                                $value = "";
                                if(isset($item_row[$column])){
                                    $value = $item_row[$column];
                                }
                                
                                $str = '_list['.$list['name'].']['.$rowID.']['.$column.']';
                                ?>
                                <td class="">
                                <input name="<?php echo $str ?>" type="text" value="<?php echo $value; ?>" />
                                </td>
                                <?php
                            }
                            ?>
                            <!-- buttons -->
                            <?php
                            foreach($row_buttons as $name => $label){
                                $str = $name.'['.$list['name'].']['.$rowID.']';
                                ?>
                                <td class="">
                                <input name="<?php echo $str; ?>" type="submit" value="<?php echo admin_label($label); ?>" />
                                </td>
								<?php
                            }
                            ?>
						</tr>
						<?php } ?>
						<!-- rows end -->
                        <!-- Add new item to tabel : -->
                        <?php _table_add($list[FW_LIST_COLUMNS]); ?>
					</table>
					
					<?php
				}else{ // count
					echo '<p> No Lists Items Available </p>';
				}
				
				
			}
		}
	}
	ui_panel_end();
}
It also uses this:

Code: Select all

// a componenet of the above function
function _table_add($columns){
	?>
	<tr class="">
		<!-- New Item -->
		<?php foreach( $columns as $column ){ ?>
		<td class="">
		<input name="_newitem[<?php echo $column; ?>]" type="text" />
		</td>
		<?php } ?>
		<td>
		<input name="_addnewlistitem" type="submit" value="Save" />
		</td>
	</tr>	
    <?php 
}
?>

        // < different php file contains this>
	// new list array structure
	function fw_list_new($name){
		return array(
			FW_LIST_SUBITEM_KEY 	=> FW_LIST_SUBITEM_KEY, // infinate depth - to identify lists inside lists
					
			'name'					=> $name,
					
			FW_LIST_ITEMS			=> array(),
			FW_LIST_ITEMS_DELETED	=> array(), // sub items are moved here when deleted
			FW_LIST_COLUMNS			=> array('name','description'), //default columns
			//'min_level_view'		=> 900,	// on Public Lists, weather only admins can view
			//'min_level_edit'		=> 900, // admins can edit on public lists 
			//'deleted'				=> false, // <-- create this entry to hide it 
			//'creator'				=> USER_CURRENT_HASH, // who created this list
			//'edited_by'				=> USER_CURRENT_HASH, // last edited by
			//'public'				=> false, // user's list can be shared?
			
			// Extra Propertied
			//'properties'			=> array(),
			FW_LIST_COMMENTS		=> array(), //<-- comments will be added as list items...
			
			'date_created'			=> date(FW_DATEFORMAT),
			'date_edited'			=> date(FW_DATEFORMAT),
		);
	}



The problem I have is that - when the lists are empty - it should display a table row containing empty fields under the available columns collected from FW LIST_COLUMNS....


The basic issue is - it simply displays nothing when FW_LIST_ITEMS array is empty... were I am expecting a table...
Might be hard to figure out just by looking at it - but I cant show more code than this publicly.

I'm posting in hope that the first set of code { ui_tablelist(); } has a really simple stupid mistake that I am overlooking somewere.
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Theres an error - But i dont see it (php)

Post by Bladerunner »

If FW_LIST_ITEMS is empty then add a blank row manually?
If I weren't insane: I couldn't be so brilliant! - The Joker
codiemorgan
Registered User
Posts: 15
Joined: 14 Jul 2010, 11:40

Re: Theres an error - But i dont see it (php)

Post by codiemorgan »

Bladerunner wrote:If FW_LIST_ITEMS is empty then add a blank row manually?

when $list[FW_LIST_ITEMS] is empty. This is supposed to display a blank row ( or table row ) containing empty cells (with inputs and a save button) - using _table_add( [array of column names] ) to generate this row

The error is exactly what u mentioned --- it isn't displaying the extra row at all when the $list[ FW_LIST_ITEMS ]

I have been dumping the arrays to test - the Columns are available in data, the list is empty - so my immediate issue is the missing "add item" row.
HuNtingGoof
Registered User
Posts: 2257
Joined: 19 Sep 2003, 02:00
Location: Durban
Contact:

Re: Theres an error - But i dont see it (php)

Post by HuNtingGoof »

Wouldn't be better to do the columns validation first and then write the columns/headers before moving onto the rows?

All I'm say is validate and then write, validate and then write.. etc


if(is_array($list)){

$continue = false;

Code: Select all

      if(isset($list[FW_LIST_COLUMNS])) {
          $columns = $list[FW_LIST_COLUMNS])
          if (count($coumns) > 0) {
              // do your column stuff
              $countue = true;
          }     
      }

      if ($continue == true) {
          if(isset($list[FW_LIST_ITEMS])) {
              $rows = $list[FW_LIST_COLUMNS])
              if (count($rows) > 0) {
                  // do your row stuff
              } else
                 // insert blank row
              }
          }
      }
This at least splits up the two different parts and probably saves you quite a few 'validation' lines.
I do apologize if some of the code is wrong.. I haven't done PHP in quite a while.. :S
Post Reply