Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Something Obvious?


  • Please log in to reply
8 replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:09:06 AM

Posted 04 February 2012 - 03:58 AM

So i haven't written in PHP for a while, but still, i don't see what i'm doing wrong here, has to be something easy! From what i can see $GridColNumber is being incremented but by the time it gets back to the top of the "loop" - casued by wpsc_start_category_query, $GridColNumber seems to be === 1?

the PHP i've got looks like this...

<div class="wpsc_categories wpsc_category_grid group">
    <table border="1" width="100%" cellpadding="0" cellspacing="0">
      <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?><?php 
        if ($GridColNumber === 1)
        {
              echo "<tr><!-- GridColNumber === $GridColNumber 1 -->";
        }
        echo "<td>";
      ?><!-- Start Product -->

      <tr>
        <td></td>
      </tr>

      <tr>
        <td><!-- Print the Image -->
         <a href="%3C?php%20wpsc_print_category_url();?%3E" class=
        "wpsc_category_grid_item &lt;?php wpsc_print_category_classes_section(); ?&gt;"
        title=
        "<?php wpsc_print_category_name(); ?>"><?php wpsc_print_category_image(get_option('category_image_width'),get_option('category_image_height')); ?></a></td>
      </tr>

      <tr>
        <td><!-- Print the Title -->
        <a href="%3C?php%20wpsc_print_category_url();?%3E" class=
        "wpsc_category_grid_item_title" title=
        "<?php wpsc_print_category_name(); ?>"><?php wpsc_print_category_name(); ?></a></td>
      </tr>
    </table><!-- End Product -->
    <?php
      echo "</td>";
      $GridColNumber = $GridColNumber + 1;
      echo "<!-- GridColNumber = $GridColNumber 1-4 -->";
      if($GridColNumber === $MaxCols)
      {
                echo "<!-- GridColNumber = MaxCols ($MaxCols) -->";
              echo "</tr>";
              $GridColNumber = 1;
      }
    ?><?php wpsc_end_category_query(); ?>
  </div><!--close wpsc_categories-->

i'm trying to get the two products to show four across then start a new row show four more etc...

this is the HTML i'm getting

<div class="wpsc_categories wpsc_category_grid group">
    <table border="1" width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <!-- GridColNumber === 1 1 -->

        <td>
          <!-- Start Product -->

          <table>
            <tr>
              <td><!-- Print the Image -->
               <a href=
              "http://tailormadesolutions.com.au/jeanjail/?wpsc_product_category=product-group-1"
              class="wpsc_category_grid_item" title="Product Group 1"></a></td>
            </tr>

            <tr>
              <td><!-- Print the Title -->
              <a href=
              "http://tailormadesolutions.com.au/jeanjail/?wpsc_product_category=product-group-1"
              class="wpsc_category_grid_item_title" title="Product Group 1">Product Group
              1</a></td>
            </tr>
          </table><!-- End Product -->
        </td><!-- GridColNumber = 2 1-4 -->
      </tr>

      <tr>
        <!-- GridColNumber === 1 1 -->

        <td>
          <!-- Start Product -->

          <table>
            <tr>
              <td><!-- Print the Image -->
               <a href=
              "http://tailormadesolutions.com.au/jeanjail/?wpsc_product_category=product-group-2"
              class="wpsc_category_grid_item" title="Product Group 2"></a></td>
            </tr>

            <tr>
              <td><!-- Print the Title -->
              <a href=
              "http://tailormadesolutions.com.au/jeanjail/?wpsc_product_category=product-group-2"
              class="wpsc_category_grid_item_title" title="Product Group 2">Product Group
              2</a></td>
            </tr>
          </table><!-- End Product -->
        </td><!-- GridColNumber = 2 1-4 -->
      </tr>
    </table>
  </div><!--close wpsc_categories-->

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:06 PM

Posted 04 February 2012 - 08:51 AM

You have not defined $maxCols anywhere.

#3 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:09:06 AM

Posted 05 February 2012 - 06:00 PM

sorry i missed a bit of code in the PHP above the div... i have $MaxCols = 4; and $GridColNumber = 1; in the few lines above

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:06 PM

Posted 05 February 2012 - 11:28 PM

we can't very well guess what the problem might be without seeing all of the PHP.

#5 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:09:06 AM

Posted 05 February 2012 - 11:49 PM

I can give you all of it (when i get home) but it's pages long and most is irrelevant (except for the piece that i missed...)

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:06 PM

Posted 06 February 2012 - 09:01 AM

You don't have any means of looping 4 times, unless that also is in the part that you didn't post.

#7 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:09:06 AM

Posted 06 February 2012 - 06:39 PM

Here's the whole php file, it's from a plugin for wordpress, i didn't like the way it was displaying the grid (only showed images not product group).
The looping is triggered by this line:
<?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?>

<?php
global $wp_query;	
$image_width = get_option('product_image_width');
/*
 * Most functions called in this page can be found in the wpsc_query.php file
 */
?>
<div id="default_products_page_container" class="wrap wpsc_container">

<?php wpsc_output_breadcrumbs(); ?>
	
	<?php do_action('wpsc_top_of_products_page'); // Plugin hook for adding things to the top of the products page, like the live search ?>
	<?php if(wpsc_display_categories()): ?>
	  <?php if(wpsc_category_grid_view()) :?>
<?php
  $GridColNumber = 1;
  $MaxCols = 4;
?>
			<div class="wpsc_categories wpsc_category_grid group">

<table border=1 width="100%" cellpadding=0 cellspacing =0>
<?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?>
<?php 
  if ($GridColNumber === 1)
  {
  	echo "<tr><!-- GridColNumber === $GridColNumber 1 -->";
  }
  echo "<td>";
?>
<!-- Start Product -->
<table><tr><td>
<!-- Print the Image -->
<a href="<?php wpsc_print_category_url();?>" class="wpsc_category_grid_item  <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name(); ?>">
	<?php wpsc_print_category_image(get_option('category_image_width'),get_option('category_image_height')); ?>
</a>
</td></tr>
<tr><td>
<!-- Print the Title -->
<a href="<?php wpsc_print_category_url();?>" class="wpsc_category_grid_item_title" title="<?php wpsc_print_category_name(); ?>"><?php wpsc_print_category_name(); ?></a>
</td></tr></table>
<!-- End Product -->
<?php
  echo "</td>";
  $GridColNumber = $GridColNumber + 1;
  echo "<!-- GridColNumber = $GridColNumber 1-4 -->";
  if($GridColNumber === $MaxCols)
  {
            echo "<!-- GridColNumber = MaxCols ($MaxCols) -->";
	  echo "</tr>";
	  $GridColNumber = 1;
  }
?>

			  <?php wpsc_end_category_query(); ?>
</table>
			</div><!--close wpsc_categories-->
	  <?php else:?>
			<ul class="wpsc_categories">
			
				<?php wpsc_start_category_query(array('category_group'=>get_option('wpsc_default_category'), 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?>
						<li>
							<?php wpsc_print_category_image(get_option('category_image_width'), get_option('category_image_height')); ?>
							
							<a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name(); ?>"><?php wpsc_print_category_name(); ?></a>
							<?php if(wpsc_show_category_description()) :?>
								<?php wpsc_print_category_description("<div class='wpsc_subcategory'>", "</div>"); ?>				
							<?php endif;?>
							
							<?php wpsc_print_subcategory("<ul>", "</ul>"); ?>
						</li>
				<?php wpsc_end_category_query(); ?>
			</ul>
		<?php endif; ?>
	<?php endif; ?>
<?php // */ ?>
	
	<?php if(wpsc_display_products()): ?>
		
		<?php if(wpsc_is_in_category()) : ?>
			<div class="wpsc_category_details">
				<?php if(wpsc_show_category_thumbnails()) : ?>
					<img src="<?php echo wpsc_category_image(); ?>" alt="<?php echo wpsc_category_name(); ?>" />
				<?php endif; ?>
				
				<?php if(wpsc_show_category_description() &&  wpsc_category_description()) : ?>
					<?php echo wpsc_category_description(); ?>
				<?php endif; ?>
			</div><!--close wpsc_category_details-->
		<?php endif; ?>
		<?php if(wpsc_has_pages_top()) : ?>
			<div class="wpsc_page_numbers_top">
				<?php wpsc_pagination(); ?>
			</div><!--close wpsc_page_numbers_top-->
		<?php endif; ?>		
		
	
		<div class="wpsc_default_product_list">
		<?php /** start the product loop here */?>
		<?php while (wpsc_have_products()) :  wpsc_the_product(); ?>
					
			<div class="default_product_display product_view_<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?> group">   
				<h2 class="prodtitle entry-title">
							<?php if(get_option('hide_name_link') == 1) : ?>
								<?php echo wpsc_the_product_title(); ?>
							<?php else: ?> 
								<a class="wpsc_product_title" href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a>
							<?php endif; ?>
						</h2>   
				<?php if(wpsc_show_thumbnails()) :?>
					<div class="imagecol" style="width:<?php echo $image_width; ?>;" id="imagecol_<?php echo wpsc_the_product_id(); ?>">
						<?php if(wpsc_the_product_thumbnail()) :
						?>
							<a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo wpsc_the_product_image(); ?>">
								<img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>

							</a>
						<?php else: ?>
								<a href="<?php echo wpsc_the_product_permalink(); ?>">
								<img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="No Image" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />	
								</a>
						<?php endif; ?>
						<?php
						if(gold_cart_display_gallery()) :					
							echo gold_shpcrt_display_gallery(wpsc_the_product_id(), true);
						endif;
						?>	
					</div><!--close imagecol-->
				<?php endif; ?>
					<div class="productcol" style="margin-left:<?php echo $image_width + 20; ?>px;" >
					
						
						
						<?php							
							do_action('wpsc_product_before_description', wpsc_the_product_id(), $wp_query->post);
							do_action('wpsc_product_addons', wpsc_the_product_id());
						?>
						
						
						<div class="wpsc_description">
							<?php echo wpsc_the_product_description(); ?>
                        </div><!--close wpsc_description-->
				
						<?php if(wpsc_the_product_additional_description()) : ?>
						<div class="additional_description_container">
							
								<img class="additional_description_button"  src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/icon_window_expand.gif" alt="Additional Description" /><a href="<?php echo wpsc_the_product_permalink(); ?>" class="additional_description_link"><?php _e('More Details', 'wpsc'); ?>
							</a>
							<div class="additional_description">
								<p><?php echo wpsc_the_product_additional_description(); ?></p>
							</div><!--close additional_description-->
						</div><!--close additional_description_container-->
						<?php endif; ?>
						
						<?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
							<?php $action =  wpsc_product_external_link(wpsc_the_product_id()); ?>
						<?php else: ?>
						<?php $action = htmlentities(wpsc_this_page_url(), ENT_QUOTES, 'UTF-8' ); ?>					
						<?php endif; ?>					
						<form class="product_form"  enctype="multipart/form-data" action="<?php echo $action; ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_<?php echo wpsc_the_product_id(); ?>" >
						<?php do_action ( 'wpsc_product_form_fields_begin' ); ?>
						<?php /** the variation group HTML and loop */?>
                        <?php if (wpsc_have_variation_groups()) { ?>
                        <fieldset><legend><?php _e('Product Options', 'wpsc'); ?></legend>
						<div class="wpsc_variation_forms">
                        	<table>
							<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
								<tr><td class="col1"><label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label></td>
								<?php /** the variation HTML and loop */?>
								<td class="col2"><select class="wpsc_select_variation" name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
								<?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
									<option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
								<?php endwhile; ?>
								</select></td></tr> 
							<?php endwhile; ?>
                            </table>
						</div><!--close wpsc_variation_forms-->
                        </fieldset>
						<?php } ?>
						<?php /** the variation group HTML and loop ends here */?>
							
							<!-- THIS IS THE QUANTITY OPTION MUST BE ENABLED FROM ADMIN SETTINGS -->
							<?php if(wpsc_has_multi_adding()): ?>
                            	<fieldset><legend><?php _e('Quantity', 'wpsc'); ?></legend>
								<div class="wpsc_quantity_update">
                                <?php /*<label for="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>"><?php _e('Quantity', 'wpsc'); ?>:</label>*/ ?>
								<input type="text" id="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>" name="wpsc_quantity_update" size="2" value="1" />
								<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
								<input type="hidden" name="wpsc_update_quantity" value="true" />
                                </div><!--close wpsc_quantity_update-->
                                </fieldset>
							<?php endif ;?>

							<div class="wpsc_product_price">
								<?php if( wpsc_show_stock_availability() ): ?>
									<?php if(wpsc_product_has_stock()) : ?>
										<div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div>
									<?php else: ?>
										<div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="out_of_stock"><?php _e('Product not in stock', 'wpsc'); ?></div>
									<?php endif; ?>
								<?php endif; ?>
								<?php if(wpsc_product_is_donation()) : ?>
									<label for="donation_price_<?php echo wpsc_the_product_id(); ?>"><?php _e('Donation', 'wpsc'); ?>: </label>
									<input type="text" id="donation_price_<?php echo wpsc_the_product_id(); ?>" name="donation_price" value="<?php echo wpsc_calculate_price(wpsc_the_product_id()); ?>" size="6" />

								<?php else : ?>
									<?php if(wpsc_product_on_special()) : ?>
										<p class="pricedisplay product_<?php echo wpsc_the_product_id(); ?>"><?php _e('Old Price', 'wpsc'); ?>: <span class="oldprice" id="old_product_price_<?php echo wpsc_the_product_id(); ?>"><?php echo wpsc_product_normal_price(); ?></span></p>
									<?php endif; ?>
									<p class="pricedisplay product_<?php echo wpsc_the_product_id(); ?>"><?php _e('Price', 'wpsc'); ?>: <span id='product_price_<?php echo wpsc_the_product_id(); ?>' class="currentprice pricedisplay"><?php echo wpsc_the_product_price(); ?></span></p>
									<?php if(wpsc_product_on_special()) : ?>
										<p class="pricedisplay product_<?php echo wpsc_the_product_id(); ?>"><?php _e('You save', 'wpsc'); ?>: <span class="yousave" id="yousave_<?php echo wpsc_the_product_id(); ?>"><?php echo wpsc_currency_display(wpsc_you_save('type=amount'), array('html' => false)); ?>! (<?php echo wpsc_you_save(); ?>%)</span></p>
									<?php endif; ?>
									
									<!-- multi currency code -->
									<?php if(wpsc_product_has_multicurrency()) : ?>
	                                	<?php echo wpsc_display_product_multicurrency(); ?>
                                    <?php endif; ?>
									
									<?php if(wpsc_show_pnp()) : ?>
										<p class="pricedisplay"><?php _e('Shipping', 'wpsc'); ?>:<span class="pp_price"><?php echo wpsc_product_postage_and_packaging(); ?></span></p>
									<?php endif; ?>							
								<?php endif; ?>
							</div><!--close wpsc_product_price-->
							
							<input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
							<input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
					
							<!-- END OF QUANTITY OPTION -->
							<?php if((get_option('hide_addtocart_button') == 0) &&  (get_option('addtocart_or_buynow') !='1')) : ?>
								<?php if(wpsc_product_has_stock()) : ?>
									<div class="wpsc_buy_button_container">
										<div class="wpsc_loading_animation">
											<img title="Loading" alt="Loading" src="<?php echo wpsc_loading_animation_url(); ?>" />
											<?php _e('Updating cart...', 'wpsc'); ?>
										</div><!--close wpsc_loading_animation-->
											<?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
											<?php $action = wpsc_product_external_link( wpsc_the_product_id() ); ?>
											<input class="wpsc_buy_button" type="submit" value="<?php echo wpsc_product_external_link_text( wpsc_the_product_id(), __( 'Buy Now', 'wpsc' ) ); ?>" onclick="return gotoexternallink('<?php echo $action; ?>', '<?php echo wpsc_product_external_link_target( wpsc_the_product_id() ); ?>')">
											<?php else: ?>
										<input type="submit" value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
											<?php endif; ?>
									</div><!--close wpsc_buy_button_container-->
								<?php endif ; ?>
							<?php endif ; ?>
							<div class="entry-utility wpsc_product_utility">
								<?php edit_post_link( __( 'Edit', 'wpsc' ), '<span class="edit-link">', '</span>' ); ?>
							</div>
							<?php do_action ( 'wpsc_product_form_fields_end' ); ?>
						</form><!--close product_form-->
						
						<?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow')=='1')) : ?>
							<?php echo wpsc_buy_now_button(wpsc_the_product_id()); ?>
						<?php endif ; ?>
						
						<?php echo wpsc_product_rater(); ?>
						
						
					<?php // */ ?>
				</div><!--close productcol-->
			<?php if(wpsc_product_on_special()) : ?><span class="sale"><?php _e('Sale', 'wpsc'); ?></span><?php endif; ?>
		</div><!--close default_product_display-->

		<?php endwhile; ?>
		<?php /** end the product loop here */?>
		</div>
		<?php if(wpsc_product_count() == 0):?>
			<h3><?php  _e('There are no products in this group.', 'wpsc'); ?></h3>
		<?php endif ; ?>
	    <?php do_action( 'wpsc_theme_footer' ); ?> 	

		<?php if(wpsc_has_pages_bottom()) : ?>
			<div class="wpsc_page_numbers_bottom">
				<?php wpsc_pagination(); ?>
			</div><!--close wpsc_page_numbers_bottom-->
		<?php endif; ?>
	<?php endif; ?>
</div><!--close default_products_page_container-->

Edited by KamakaZ, 06 February 2012 - 06:43 PM.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#8 tripflex

tripflex

  • Members
  • 128 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Orlando, FL
  • Local time:06:06 PM

Posted 06 March 2012 - 10:09 PM

Line 24:
if ($GridColNumber === 1)

Line 46:
if($GridColNumber === $MaxCols)

No need to use identical (===) operator here, you can just use the simple equal (==) since we're only comparing a value.

This is one of my bookmarks, good reference:
http://www.w3schools.com/php/php_operators.asp

So if i'm understanding you correctly you're trying to make it display 4 across, correct?

http://tailormadesolutions.com.au/jeanjail/?page_id=4

So if there were 4 of them it would so all 4 in the same row, if there were 8 it would show 2 rows (up and down) and 4 cells (left to right)...correct?

Well...add two more products so we can fix the problem...it's only showing 2 products right now.
There's no place like 0.0.0.0, i'm tired of being at 127.0.0.1

#9 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:09:06 AM

Posted 18 March 2012 - 06:08 PM

So if there were 4 of them it would so all 4 in the same row, if there were 8 it would show 2 rows (up and down) and 4 cells (left to right)...correct?

Well...add two more products so we can fix the problem...it's only showing 2 products right now.


In regards to the appearance, correct, 4 products = one line, 8 products = 2 lines etc...

The problem is not the amount of rows it's showing, it isn't even showing the tables correctly.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users