unplugged_web Posted May 20, 2015 Share Posted May 20, 2015 I really need some help with this please. I'm trying to display a list of products rather than just one. This is what I'm using to display a group of products. But at the moment it shows one main product then a smaller list of the rest. <?php product_display( $collection[$dynaload]['products'],"More Products:",1 ) ?> If I change it to <?php product_display( $collection[$dynaload]['products'],"More Products:",,0,0,0,1 ) ?> then it shows the remain products in a vertical list Ideally I'd like to be able to display all of the products (or if not then choose how many to display) but I don't know the code well enough to know how to change that. This is the product_display function: function product_display() { # load arguments if( func_num_args()==2 ) { $products_list=func_get_arg(0); $title=func_get_arg(1); $featured=0; $sortable=0; $showall=0; $cols=5; } elseif( func_num_args()==3 ) { $products_list=func_get_arg(0); $title=func_get_arg(1); $featured=func_get_arg(2); $sortable=0; $showall=0; $cols=5; } elseif( func_num_args()==4 ) { $products_list=func_get_arg(0); $title=func_get_arg(1); $featured=func_get_arg(2); $sortable=func_get_arg(3); $showall=0; $cols=5; } elseif( func_num_args()==5 ) { $products_list=func_get_arg(0); $title=func_get_arg(1); $featured=func_get_arg(2); $sortable=func_get_arg(3); $showall=func_get_arg(4); $cols=5; } elseif( func_num_args()==6 ) { $products_list=func_get_arg(0); $title=func_get_arg(1); $featured=func_get_arg(2); $sortable=func_get_arg(3); $showall=func_get_arg(4); $cols=func_get_arg(5); } # initialise $row=1; $ctr=1; # remove old products if( is_array( $products_list ) ) { foreach( $products_list as $key=>$value ) { if( $GLOBALS['products_complete'][$key]['level']==4 ) { unset( $products_list[$key] ); } } } # check and set featured if( $GLOBALS['bit1']=="popular" ) { $featured=0; } if( $featured ) { $found=0; foreach( $products_list as $key=>$value ) { if( !$found ) { $boxed=$key; $boxedr=$GLOBALS['products_complete'][$boxed]['id']; unset( $products_list[$key] ); $found=1; } } # get bullets usedb( $GLOBALS['country_modules'][$GLOBALS['ccode2']]['db_web'],"dbLinkInt" ); $query="select * from product_bullets3 where product_id=".$boxedr." and country like "%".$GLOBALS['ccode2']."%" order by pos"; $product_bullets=dbselect( $query,"dbLinkInt" ); # set first bullet as short title if it is empty if( empty( $GLOBALS['products_complete'][$boxed]['short_title'] ) && !empty( $product_bullets[0]['text'] ) ) { $GLOBALS['products_complete'][$boxed]['short_title']=$product_bullets[0]['text']; unset( $product_bullets[0] ); } # get symbols $query="select name,image from product_symbols,product_symbols_map where symbol_id=product_symbols.id and visible=1 and product_id=".$boxedr." order by name"; $product_symbols=dbselect( $query,"dbLinkInt" ); # featured image if( is_file( $GLOBALS['install_dir']."/images/dynamic/".$GLOBALS['products_complete'][$boxed]['graphics'][10]['filename_image'] ) ) { $img="/images/dynamic/".$GLOBALS['products_complete'][$boxed]['graphics'][10]['filename_image']; } else { $img="/images/site/missing1.jpg"; } # featured box title # echo '<div class="box-head"><span>Best-seller</span></div>'; # featured main box echo '<div style="margin: 0; padding: 0;">'; echo ' details here'; echo '</div>'; echo '<script type="text/javascript">'; echo ' $(".sym").hover( function(){'; echo ' var id=$(this).attr("id").replace( "sym-","ttip-" );'; echo ' $("#"+id).show();'; echo ' },function(){'; echo ' $(".ttip").hide();'; echo ' });'; echo '</script>'; } echo $GLOBALS['html_clear']; # sorting if( $sortable ) { if( $sortable=="alpha_down" ) { if( is_array( $products_list ) ) { $products_list=array_reverse( $products_list,true ); } } elseif( $sortable=="rate_good" ) { if( is_array( $products_list ) ) { foreach( $products_list as $key=>$value ) { $temp[$key]=$GLOBALS['products_complete'][$key]['rating_cnt']+$GLOBALS['products_complete'][$key]['rating_offset']; } asort( $temp ); $products_list=$temp; unset( $temp ); } } elseif( $sortable=="rate_bad" ) { if( is_array( $products_list ) ) { foreach( $products_list as $key=>$value ) { $temp[$key]=$GLOBALS['products_complete'][$key]['rating_cnt']+$GLOBALS['products_complete'][$key]['rating_offset']; } asort( $temp ); $products_list=$temp; unset( $temp ); $products_list=array_reverse( $products_list,true ); } } elseif( $sortable=="price_high" ) { if( is_array( $products_list ) ) { foreach( $products_list as $key=>$value ) { $temp[$key]=$GLOBALS['products_complete'][$key]['price1']; } asort( $temp ); $products_list=$temp; unset( $temp ); } } elseif( $sortable=="price_low" ) { if( is_array( $products_list ) ) { foreach( $products_list as $key=>$value ) { $temp[$key]=$GLOBALS['products_complete'][$key]['price1']; } asort( $temp ); $products_list=$temp; unset( $temp ); $products_list=array_reverse( $products_list,true ); } } } # calculate last row $prods=0; if( is_array( $products_list ) ) { foreach( $products_list as $key=>$value ) { if( !isset( $GLOBALS['products_complete'][$key]['nodisplay'] ) || $showall==1 ) { $prods++; } } $lastrow=ceil( $prods/$cols ); } if( is_array( $products_list ) ) { echo '<div class="products"'; if( $cols==1 ) { echo ' style="padding: 0 12px;"'; } echo '>'; foreach( $products_list as $key=>$value ) { if( !isset( $GLOBALS['products_complete'][$key]['nodisplay'] ) || $showall==1 ) { # start line box if( $ctr==1 ) { echo '<div class="productlist-line"'; if( $row==$lastrow ) { echo ' style="border: 0; margin: 0; padding: 0;"'; } echo '>'; } # product float echo '<div class="rest'; if( $ctr==$cols ) { echo " productlist-last"; } echo'">';echo 'text here'; echo '</div>'; $ctr++; if( $ctr>$cols ) { $ctr=1; $row++; } # end line box if( $ctr==1 ) { echo $GLOBALS['html_clear'].'</div>'; } } } if( $ctr!=1 ) { echo $GLOBALS['html_clear'].'</div>'; } echo '</div>'; } } Link to comment Share on other sites More sharing options...
Ingolme Posted May 20, 2015 Share Posted May 20, 2015 Did the person who wrote that function provide any documentation? Link to comment Share on other sites More sharing options...
unplugged_web Posted May 20, 2015 Author Share Posted May 20, 2015 Did the person who wrote that function provide any documentation? Unfortunately no they didn't. Link to comment Share on other sites More sharing options...
Ingolme Posted May 20, 2015 Share Posted May 20, 2015 It looks like you can just manually go through your list of products without using that function: foreach($collection[$dynaload]['products'] as $product) { // HTML and product information go here} Link to comment Share on other sites More sharing options...
unplugged_web Posted May 20, 2015 Author Share Posted May 20, 2015 It looks like you can just manually go through your list of products without using that function: foreach($collection[$dynaload]['products'] as $product) { // HTML and product information go here} Sorry to be so dumb but which part would I change? All of it or just the actual function? Link to comment Share on other sites More sharing options...
Ingolme Posted May 20, 2015 Share Posted May 20, 2015 What you would do is substitute this line: <?php product_display( $collection[$dynaload]['products'],"More Products:",1 ) ?> with a foreach() loop that goes through the object. You need to know the object's properties to do it. In the foreach loop you can use whatever HTML you want. Link to comment Share on other sites More sharing options...
unplugged_web Posted May 21, 2015 Author Share Posted May 21, 2015 What you would do is substitute this line: <?php product_display( $collection[$dynaload]['products'],"More Products:",1 ) ?> with a foreach() loop that goes through the object. You need to know the object's properties to do it. In the foreach loop you can use whatever HTML you want. I tried to do that but it didn't seem to load any of the products. I thought I knew the objects properties but I guess not. Also there's quite a number of tables that hold the details of the products - will this still work? Link to comment Share on other sites More sharing options...
Ingolme Posted May 21, 2015 Share Posted May 21, 2015 I don't know what your data structures look like. If you want to know what properties an object contains, call var_dump() on it. var_dump($collection[$dynaload]['products']); This is just for testing, I wouldn't put it on a live website. Link to comment Share on other sites More sharing options...
unplugged_web Posted May 21, 2015 Author Share Posted May 21, 2015 I don't know what your data structures look like. If you want to know what properties an object contains, call var_dump() on it. var_dump($collection[$dynaload]['products']); This is just for testing, I wouldn't put it on a live website. Thanks, I'll give that a go Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now