Jump to content
Sign in to follow this  
sciulli

How to format the results of an array

Recommended Posts

I'm trying to develop a page that will display groupings of links based on purchase (defined by product type . order status and purchase date). Example: display all listings within the past year for completed purchases of product #2. I'm using options_type contribution for text input fields. What I would like the mod to do is return query results as follows:

 

(oa.order_id) (oa.products_options) (oa.products_options_values)

 

4 Title This is my title

4 Ad This is my text

4 URL http://url.com

 

5 Title This is my title1

5 Ad This is my text1

5 URL http://url1.com

 

and print out as

 

(bold)This is my title

(italic)This is my text

(url)http://url.com

 

(bold)This is my title1

(italic)This is my text1

(url)http://url1.com

 

Instead, all the results are underlined, only the first letter of each row is being returned and they are in random order.

 

	  $end_date = strftime ("%Y-%m-%d", strtotime("-1 year"));


	  $result = tep_db_query("select oa.products_options as title, oa.products_options_values as value from orders_products op, orders o, orders_products_attributes oa where op.products_id = 2 and o.date_purchased > '. $end_date .' and o.orders_id = op.orders_id and o.orders_id = oa.orders_id AND o.orders_status =3");

while ( $row = tep_db_fetch_array($result))
{


foreach ($row as $rows) { 

	if ($row['oa.products_options'] == 'Title') { 
		// title selected - print bold 
		print '<B>'.$rows['oa.products_options_values'].'</B><BR>'; 
	} 

	else if ($row['oa.products_options'] == 'Ad') { 
		// ad selected - print italic 
		print '<i>'.$rows['oa.products_options_values'].'</i><BR>'; 
	} 

	else if ($row['oa.products_options'] == 'URL') { 
		// url selected - print link 
		print '<a href='.$rows['oa.products_options_values'].'>'.$rows['oa.products_options_values'].'</a><BR>'; 
	} 

	else {	
		// other category - print regular 
		print '<u>'.$rows['oa.products_options_values'].'</u><BR>'; 
	} 

} // end foreach


}

 

I've copied/pasted snippets from all over so it's terrible code and reading about php arrays isn't getting me anywhere. Any help is appreciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×