Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need help to sort code for columns


241

Recommended Posts

I need a little help with some code

 

This is what I have so far:

 

 ?if (sizeof($name_of_array) <> '0') { 
? $col = 0; 
? ?for($i=0; $i<sizeof($name_of_array); $i++) { ?
? $col++;

 

this is then followed by the layout which closes with a } then this:

 

 ? if (($col / NAME_OF_COLUMNS) == floor($col / NAME_OF_COLUMNS)) { 
echo '</td></tr><tr><td colspan="' . NAME_OF_COLUMNS . '" align="right" valign="top" class="main"><hr color=#' . NAME_OF_LINE_COLOUR . '></td></tr><tr>'; 
?}else{
echo '</td></tr><tr><td colspan="' . NAME_OF_COLUMNS . '" align="right" valign="top" class="main"></td></tr>'; 
?}
?}
if (($i+1) != sizeof($featured_manufacturers_array)) { 
? ? ?}
echo '</table>';

 

the issue is thus:

 

I can get the layout to be thus when the colums are set to 3 by moving the closing } :

 

1 2 3 4 5 6 7 etc

 

or

 

1

2

3

4

5

6

7

etc

 

 

but it is meant to be:

 

1 2 3

4 5 6

7 etc

 

What have I missed out :blink:

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

Take a look at how categories are done - you should be able to adapt this:

 

    $number_of_categories = tep_db_num_rows($categories_query);

   $rows = 0;
   while ($categories = tep_db_fetch_array($categories_query)) {
     $rows++;
     $cPath_new = tep_get_path($categories['categories_id']);
     $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
     echo '                <td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $categories['categories_name'] . '</a></td>' . "\n";
     if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories)) {
       echo '              </tr>' . "\n";
       echo '              <tr>' . "\n";
     }
   }

 

Take out all the stuff like links you won't need to simplify it - then adapt :)

 

Matti

Link to comment
Share on other sites

Ok Matti I will give that a go

 

I should have initially given more information in that the queries are being done by another page that then calls the above coded page via a require.

 

Would that make any difference if yes then should I also post the codes for that section.

 

Is it a case of a missing count on the number of items as I see that the code provided gives a string for the number of categories

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

Yes - I was confused as to the meaning of your define NAME_OF_COLUMNS - I didn't really have time to take a thorough look at what you were doing, but saw the similarity to what I posted - I often will rework something I know works :)

 

If your code is called by a require then your variables will (should) be set - you can always use the following to check a variable:

 

var_dump($variable);

 

Matti

Link to comment
Share on other sites

Just a thought Steve, and I may be way off without seeing the rest of the code, but I'm wondering if you are running into a rounding problem? If the result of floor is 11.99999, for example, you will get 11.0 but you may actually want 12.0. Have you tried using echo to see the actual results of the comparison?

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

There are a few contribs that will display the products in columns for you if that is what you are after, if not, take a look to see how they handle it.

 

Ryan

If I was crafty, this would be a funny signature.

Link to comment
Share on other sites

You'll need to post more code, as to get a solution from wht you've posted would be like finding a needle in a haystack...

 

Can you post the whole code you have, and also detail exactly what the end result should be...

Link to comment
Share on other sites

Sorry I had not posted back, was not getting notified of posts.

 

 

Ok for you guys the purpose is to set featured manufacturers for this part of the code contribution.

 

this is the code for the query.

 

<?php
if(FEATURED_MANUFACTURERS_DISPLAY == 'true') 
? ?{

?$featured_manufacturers_id = $manufacturers_id; 
?
?if ((!isset($featured_manufacturers_id)) || ($featured_manufacturers_id == '0')) {
?$featured_manufacturers_query_raw = "SELECT m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, m.manufacturers_featured_until, mi.manufacturers_id, mi.languages_id, mi.manufacturers_url from " . TABLE_MANUFACTURERS 
. " m, " . TABLE_MANUFACTURERS_INFO . " mi where m.manufacturers_id = mi.manufacturers_id and mi.languages_id = '" . (int)$languages_id . "' and m.manufacturers_featured = '1' order by m.manufacturers_id 
?" . FEATURED_DIRECTION . " limit " . MAX_DISPLAY_FEATURED_MANUFACTURERS; 
?}

?$featured_manufacturers_query = tep_db_query($featured_manufacturers_query_raw); 
?while ($featured_manufacturers = tep_db_fetch_array($featured_manufacturers_query)) { 

? ?$featured_manufacturers_array[] = array('id' => $featured_manufacturers['manufacturers_id'], 
?'name' => $featured_manufacturers['manufacturers_name'], 
?'image' => $featured_manufacturers['manufacturers_image'],
?'url' => $featured_manufacturers['manufacturers_url']); 
?}

?require(DIR_WS_MODULES ?. FILENAME_FEATURED_MANUFACTURERS); 

} else // If it's disabled, then include the original New Products box 
? ?{ if(FEATURED_PRODUCTS_NEW_DISPLAY == 'true') {
? ? ?include (DIR_WS_MODULES . FILENAME_NEW_PRODUCTS); }
? ?} 
?>

 

and this is the code that the require calls:

<?php
echo '<table border="0" width="100%" cellspacing="2" cellpadding="4"><tr>';
?if (sizeof($featured_manufacturers_array) <> '0') { ? 
? $col = 0; 
? ?for($i=0; $i<sizeof($featured_manufacturers_array); $i++) { ?
? $col++; 
?>
<?php
echo '<td valign="top" align="center">';
echo '<table border="0" cellspacing="2" cellpadding="2"><tr><td width="'; SMALL_IMAGE_WIDTH + 25;
echo '" align="center" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . $featured_manufacturers_array[$i]['image'], $featured_manufacturers_array[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br><b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $featured_manufacturers_array[$i]['id'], 'NONSSL') . '"><u>' . $featured_manufacturers_array[$i]['name'] . '</u></a></b>';
echo '</td><td align="right" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . ('pixel_' . MANUFACTURERS_VLINE_IMAGE_COLOUR . '.gif'), '', '1', MANUFACTURERS_VLINE_IMAGE_HEIGHT) . '<td></tr></table></td>';
?}
?>
<?php
?if (($col / FEATURED_MANUFACTURERS_COLUMNS) == floor($col / FEATURED_MANUFACTURERS_COLUMNS)) {
echo '</tr><tr><td colspan="' . FEATURED_MANUFACTURERS_COLUMNS . '" align="right" valign="top" class="main"><hr color=#' . MANUFACTURERS_HORIZONTAL_LINE_COLOUR . '></td></tr><tr>'; 
?}else{
echo '</tr><tr><td colspan="' . FEATURED_MANUFACTURERS_COLUMNS . '" align="right" valign="top" class="main"></td></tr>';
}
}
?if (($i+0) != sizeof($featured_manufacturers_array)) { 
? ? ?}
echo '</table>';
?>

 

burt

 

the end result is given above and should be

123

456

789

 

where the columns are set to 3

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

I'll stick with what I posted before - try:

 

<?php
? ? ?if(FEATURED_MANUFACTURERS_DISPLAY == 'true') {

? ? ?include (DIR_WS_MODULES ?. FILENAME_FEATURED_MANUFACTURERS); 
?
? } else // If it's disabled, then include the original New Products box 
? 
? { if(FEATURED_PRODUCTS_NEW_DISPLAY == 'true') {
? ? include (DIR_WS_MODULES . FILENAME_NEW_PRODUCTS); }
? }
?> ?

 

and your new file:

 

<?php
? ?$featured_manufacturers_query = tep_db_query("select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image, m.manufacturers_featured_until, mi.manufacturers_id, mi.languages_id, mi.manufacturers_url from " . TABLE_MANUFACTURERS . " m, " . TABLE_MANUFACTURERS_INFO . " mi where m.manufacturers_id = mi.manufacturers_id and m.manufacturers_featured = 1 and mi.languages_id = '" . (int)$languages_id . "' order by m.manufacturers_id limit " . MAX_DISPLAY_FEATURED_MANUFACTURERS); 
? ?$number_of_manufacturers = tep_db_num_rows($featured_manufacturers_query);

? if (tep_not_null($number_of_manufacturers)) {
? echo '<tr><td><table border="0" width="100%" cellspacing="2" cellpadding="4"><tr>'; ?

? while ($featured_manufacturers = tep_db_fetch_array($featured_manufacturers_query)) {
? ? $rows++;
? ? $cPath = $featured_manufacturers['manufacturers_id'];
? ? $width = (int)(100 / FEATURED_MANUFACTURERS_COLUMNS) . '%';
? ? echo ' ? ? ? ? ? ? ? ?<td align="center" class="main" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . $featured_manufacturers['manufacturers_image'], $featured_manufacturers['manufacturers_name'], SMALL_IMAGE_WIDTH + 25, SMALL_IMAGE_HEIGHT) . '<br><u>' . $featured_manufacturers['manufacturers_name'] . '</u></a></td><td align="right" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . ('pixel_' . MANUFACTURERS_VLINE_IMAGE_COLOUR . '.gif'), '', '1', MANUFACTURERS_VLINE_IMAGE_HEIGHT) . '<td>' . "\n";
? ? if ((($rows / FEATURED_MANUFACTURERS_COLUMNS) == floor($rows / FEATURED_MANUFACTURERS_COLUMNS)) && ($rows != $number_of_manufacturers)) {
? ? ? echo ' ? ? ? ? ? ? ?</tr>' . "\n";
? ? ? echo ' ? ? ? ? ? ? ?<tr>' . "\n";
? ? }
? }
? echo '</table></td></tr>';
}
?>

 

I think this may be close :P

 

Your code above links to FILENAME_PRODUCT_INFO according to manufacturer - this does not work :) I have changed this to FILENAME_DEFAULT which does B)

 

Matti

Link to comment
Share on other sites

I think the problem is in closing } for "for" loop. Check the below code:

 

<?php

echo '<table border="0" width="100%" cellspacing="2" cellpadding="4"><tr>';

if (sizeof($featured_manufacturers_array) <> '0') { 

  $col = 0;

  for($i=0; $i<sizeof($featured_manufacturers_array); $i++) { 

  $col++;

?>

<?php

echo '<td valign="top" align="center">';

echo '<table border="0" cellspacing="2" cellpadding="2"><tr><td width="'; SMALL_IMAGE_WIDTH + 25;

echo '" align="center" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . $featured_manufacturers_array[$i]['image'], $featured_manufacturers_array[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br><b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $featured_manufacturers_array[$i]['id'], 'NONSSL') . '"><u>' . $featured_manufacturers_array[$i]['name'] . '</u></a></b>';

echo '</td><td align="right" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . ('pixel_' . MANUFACTURERS_VLINE_IMAGE_COLOUR . '.gif'), '', '1', MANUFACTURERS_VLINE_IMAGE_HEIGHT) . '<td></tr></table></td>';

// moved down }

?>

<?php

if (($col / FEATURED_MANUFACTURERS_COLUMNS) == floor($col / FEATURED_MANUFACTURERS_COLUMNS)) {

echo '</tr><tr><td colspan="' . FEATURED_MANUFACTURERS_COLUMNS . '" align="right" valign="top" class="main"><hr color=#' . MANUFACTURERS_HORIZONTAL_LINE_COLOUR . '></td></tr><tr>';

}else{

echo '</tr><tr><td colspan="' . FEATURED_MANUFACTURERS_COLUMNS . '" align="right" valign="top" class="main"></td></tr>';

  }

} // closed "for' loop

}

if (($i+0) != sizeof($featured_manufacturers_array)) {

    }

echo '</table>';

?>

Link to comment
Share on other sites

I think the below code is more clear:

 

<?php

echo '<table border="0" width="100%" cellspacing="2" cellpadding="4"><tr>';

if (sizeof($featured_manufacturers_array) <> '0') { 

  $col = 0;

  for($i=0; $i<sizeof($featured_manufacturers_array); $i++) { 

  $col++;

?>

<?php

echo '<td valign="top" align="center">';

echo '<table border="0" cellspacing="2" cellpadding="2"><tr><td width="'; SMALL_IMAGE_WIDTH + 25;

echo '" align="center" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . $featured_manufacturers_array[$i]['image'], $featured_manufacturers_array[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br><b><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $featured_manufacturers_array[$i]['id'], 'NONSSL') . '"><u>' . $featured_manufacturers_array[$i]['name'] . '</u></a></b>';

echo '</td><td align="right" valign="top" class="main">' . tep_image(DIR_WS_IMAGES . ('pixel_' . MANUFACTURERS_VLINE_IMAGE_COLOUR . '.gif'), '', '1', MANUFACTURERS_VLINE_IMAGE_HEIGHT) . '</td></tr></table></td>';

?>

<?php

if (($col / FEATURED_MANUFACTURERS_COLUMNS) == floor($col / FEATURED_MANUFACTURERS_COLUMNS)) {

echo '</tr><tr><td colspan="' . FEATURED_MANUFACTURERS_COLUMNS . '" align="right" valign="top" class="main"><hr color=#' . MANUFACTURERS_HORIZONTAL_LINE_COLOUR . '></td></tr><tr>';

$col = 0; // column reset

  }

} // closed "for' loop

}

if (($i+0) != sizeof($featured_manufacturers_array)) {

    }

echo '</table>';

?>

Link to comment
Share on other sites

Matti

 

This works as I have tried this before however it does not work if you include the original code section to draw the seperation line as in the layout that I have given, it is at this point that the layout breaks and it is this part that I cannot get beyond.

 

I can get the layout but not with the divider which is a crucial element to what I am trying to achieve.

 

I need it to be if the columns are stated as 3 that the layout will give

 

123 across the page then a line divider then 456 across the page then a line divider and for the last row to have no divider.

 

Does this code use columns?

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

I think the below code is more clear:

 

$col = 0; // column reset

? }

} // closed "for' loop

I have tried as posted earlier to move the } //closed "for" loop

 

however I notice that you have placed $col=0; lower down and that you have removed the else part. Removal of the else is not an option. The line divider is drawn between rows and the final row has no line divider.

 

I tried the code and it results in a blank page.

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

I think the below code is more clear:

 

$col = 0; // column reset

? }

} // closed "for' loop

I have tried as posted earlier to move the } //closed "for" loop

 

however I notice that you have placed $col=0; lower down and that you have removed the else part. Removal of the else is not an option. The line divider is drawn between rows and the final row has no line divider.

 

I tried the code and it results in a blank page.

My bad forgot all the changes made earlier to use Matti's code ik this is now very close to what I am after however I still have the divider below the last row.

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

My thanks to those whom helped I now have this section working and can move onto the other sections.

 

The solution was to remove my blindness to the else part as Kagg had shown, however it does not appear to need the $col=0; as this is used earlier and an extra </tr> to the tag to close the table was required.

 

I think that the code provided by Matti may inadvertently provide a solution for one of the other sections with a few additions to the code.

No longer giving free advice. Please place deposit in meter slot provided.  Individual: [=] SME: [==] Corporation: [===]
If deposit does not fit one of the slots provided then you are asking too much! :P

Is your Osc dated try Phoenix  raising oscommerce from the ashes.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...