Transformer un tableau en un tableau à deux dimensions.

Petit nouveau ! | 5 Messages

20 janv. 2011, 12:25

Bonjour,

Comme l'indique le titre, je cherche à transformer un tableau qui s'étend sur une ligne , (titre + valeur en dessous) en un tableau a 2 dimensions (titre + 2 valeurs en dessous) mais je galère, je débute en php et les tutos, qui sont pourtant bien fait ! ne partent forcément pas a partir d'un code déjà existant..

Voici le code :
<?php
$data =array(); // Holds the rows of products
$i = 1; $row = 0; // Counters


// Table header
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_FORM_THUMB_IMAGE');
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_SKU');

$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_DESC_TITLE');
/*$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_DESC_TITLE');*/
if( _SHOW_PRICES && $auth['show_prices'] ) {
	$tableheader[] = $VM_LANG->_('PHPSHOP_CART_PRICE');
}	
if( _SHOW_PRICES && $auth['show_prices'] && USE_AS_CATALOGUE != '1' ) {
	$tableheader[] = $VM_LANG->_('PHPSHOP_CART_ACTION');
}



// Creates a new HTML_Table object that will help us
// to build a table holding all the products
$table = new HTML_Table('width="100%"');

$table->addRow( $tableheader, 'class="sectiontableheader"', 'th', true );

foreach( $products as $product ) {
		
		foreach( $product as $attr => $val ) {
			// Using this we make all the variables available in the template
			// translated example: $this->set( 'product_name', $product_name );
			$this->set( $attr, $val );
		}
		
	
		$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
						. ps_product::image_tag( $product['product_thumb_image'] )
						. '</a>';
					
		$data[$row][] = $product['product_sku'];
        $data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'.$product['product_name'].'</a>';	
		if( _SHOW_PRICES && $auth['show_prices'] ) {
			$data[$row][] = $product['product_price'];
		}		
		$data[$row][] = $product['product_s_desc'];
		if( $product['has_addtocart'] ) {
			$data[$row][] = $product['form_addtocart'];
		}
		else {
			$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
							.	$product['product_details']
							.	'</a>';
		}		
		
		$row++;
		
}


// Loop through each row and build the table
foreach($data as $key => $value) {
	
	$table->addRow( $data[$key], 'class="sectiontableentry'.$i.'"', 'td', true );
	$i = $i == 1 ? 2 : 1;
}
// Display the table
echo $table->toHtml();
?>
Par exemple, mettre les variables
$data[$row][] = $product['product_sku'];  
et
                $data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
                                                . ps_product::image_tag( $product['product_thumb_image'] )
                                                . '</a>';
sur la meme division dans le tableau...

Une idée ? Merci pour votre aide :wink:

ViPHP
xTG
ViPHP | 7331 Messages

20 janv. 2011, 12:29

$data[$row][] = array( 'url' => '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
                                                . ps_product::image_tag( $product['product_thumb_image'] )
                                                . '</a>',
                                  'product_sku' => $product['product_sku']);
Ainsi ?

Petit nouveau ! | 5 Messages

20 janv. 2011, 12:37

Salut,

Cela me donne un page blanche..

Après j'ai supprimer bettement les deux variable et mis ce code a la place..quelque chose me dit que c' est pas la bonne maniere de procéder ^^

ViPHP
xTG
ViPHP | 7331 Messages

20 janv. 2011, 12:46

Bah en tout cas c'est ce que tu as demandé. ;)
Mais du fait il faut penser à modifier le code qui construit le tableau html avec ce nouveau type de tableau.

Petit nouveau ! | 5 Messages

20 janv. 2011, 16:53

Bon, je vais faire sans, j'ai déja perdu trop de temps dessus..

Merci pour ton aide