sorting arrays

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
juliekate
Registered User
Posts: 779
Joined: Sun May 05, 2002 5:32 pm
Location: Philadelphia
Contact:

sorting arrays

Post by juliekate » Wed Mar 16, 2005 2:40 pm

Hiya :)

I've been reading about arrays over and over and I'm not getting it.

I have a merchandise mod that displays a type (category) and then all the products inside it.

However I'd like it to sort by size from S -> XL, and I know it has something to do with assigning the array keys, and then sorting it, or something, but I'm really lost on this.

Here's the sql:

Code: Select all

// Get all types and merch
			$sql = "SELECT DISTINCT t.type_name, t.type_picture, t.type_desc, t.type_shipping, s.prod_name, s.prod_id, s.prod_type, s.price, s.color, s.details, s.size, s.stock 
			FROM ". TYPE ." AS t
			INNER JOIN ". STOCK ." AS s ON t.type_name = s.prod_name
				ORDER BY t.type_name DESC";
			if( !($result = $db->sql_query($sql)) )
				{
					message_die(GENERAL_ERROR, 'Could not query type list', '', __LINE__, __FILE__, $sql);
				}
			
			$merch = "";
			while( $row = $db->sql_fetchrow($result) )
			{
				$k++;
				$row_class = ( !($k % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

				if ( $row['type_name'] != $merch )
				{
				
				     $template->assign_block_vars('typerow', array(
					'ROW_CLASS' => $row_class,
					'NAME' => $row['type_name'],
					'PIC' => $row['type_picture'],
					'DESC' => $row['type_desc'],
					'SHIP' => $row['type_shipping'])
					);
				$merch = $row['type_name'];
				}
				
				if ( $row['stock'] == 0)
				{
					$stock = '<span class="gensmall"><font color=red>Sold out</font></span>';
				}
				else
				{
					$stock = $row['stock'];
				}
			
					$template->assign_block_vars('typerow.merchrow', array(
						'ROW_CLASS' => $row_class,
						'PNAME' => $row['prod_name'],
						'ID' => $row['prod_id'],
						'TYPE' => $row['prod_type'],
						'COLOR' => $row['color'],
						'SIZE' => $row['size'],
						'DETAILS' => $row['details'],
						'PRICE' => $row['price'],
						'STOCK' => $stock)
						);
				
			}
		
Where would I assign the $row['size'] array? And how do I set keys for it, and then usort?

Post Reply

Return to “[2.0.x] MOD Writers Discussion”