Zen Cart Logo
Forums / General Questions / Need help with a query

Need help with a query

Views: 2,691

Results 1 to 20 of 36
8 Mar 2016, 5:47 PM
#1
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Need help with a query

I created a page from the ezpages for my manufacturers. I have over 300. What I would like to do is have A-Z at the top, and then a section for each letter and have the query list all manufacturers for that letter but I have no clue how to go about it.

This is what I had in mind:
Attachment 16088

Can anyone assist with a script?

Thanks,

Clint

8 Mar 2016, 9:52 PM
#2
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Need help with a query

I don't have allot of time to go into detail, maybe someone else can chime in in my absence but this should get you started.

I put this right in the define page:

<?php

    for ($i=65; $i<91; $i++) {
    echo '<a href="'.chr($i).'">' . chr($i) . '</a>';
    }
    for ($i=48; $i<58; $i++) {
    echo '<a href="'.chr($i).'">' . chr($i) . '</a>';
    }

echo '<br class="clearBoth" />';


$manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name"; 

$manufacturers = $db->Execute($manufacturers_query);

while (!$manufacturers->EOF) {

    if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) {
        $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1));
        echo '<a name="#'.$initial.'">' . $initial . '</a><br />----------<br />';
    }
    echo $manufacturers->fields['manufacturers_name'] . '<br />';

      $manufacturers->MoveNext();
    }
?>
9 Mar 2016, 1:59 AM
#3
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

rbarbour:

I don't have allot of time to go into detail, maybe someone else can chime in in my absence but this should get you started.

I put this right in the define page:

<?php for ($i=65; $i<91; $i++) { echo '<a href="'.chr($i).'">' . chr($i) . '</a>'; } for ($i=48; $i<58; $i++) { echo '<a href="'.chr($i).'">' . chr($i) . '</a>'; } echo '<br class="clearBoth" />'; $manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name"; $manufacturers = $db->Execute($manufacturers_query); while (!$manufacturers->EOF) { if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) { $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1)); echo '<a name="#'.$initial.'">' . $initial . '</a><br />----------<br />'; } echo $manufacturers->fields['manufacturers_name'] . '<br />'; $manufacturers->MoveNext(); } ?>

Thank you!

What do you mean by put it in the define page?  If I created the page with EZ-Page, where do I find it?

Clint
9 Mar 2016, 2:00 AM
#4
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

rbarbour:

I don't have allot of time to go into detail, maybe someone else can chime in in my absence but this should get you started.

I put this right in the define page:

<?php for ($i=65; $i<91; $i++) { echo '<a href="'.chr($i).'">' . chr($i) . '</a>'; } for ($i=48; $i<58; $i++) { echo '<a href="'.chr($i).'">' . chr($i) . '</a>'; } echo '<br class="clearBoth" />'; $manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name"; $manufacturers = $db->Execute($manufacturers_query); while (!$manufacturers->EOF) { if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) { $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1)); echo '<a name="#'.$initial.'">' . $initial . '</a><br />----------<br />'; } echo $manufacturers->fields['manufacturers_name'] . '<br />'; $manufacturers->MoveNext(); } ?>

Thank you!

What do you mean by put it in the define page?  If I created the page with EZ-Page, where do I find it?

Clint
9 Mar 2016, 12:51 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,099
Plugin Contributions:
56

Re: Need help with a query

EZ-pages can't include imbedded PHP; that's where the "simple" pages like the "About Us Page" (available for download in the Plugins section) come in. rbarbour was referring to the language-specific page that can be edited via Tools->Define Pages Editor and included in one of those "simple" pages.

9 Mar 2016, 3:03 PM
#6
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

lat9:

EZ-pages can't include imbedded PHP; that's where the "simple" pages like the "About Us Page" (available for download in the Plugins section) come in. rbarbour was referring to the language-specific page that can be edited via Tools->Define Pages Editor and included in one of those "simple" pages.

Ok, now I'm following. So if I use page_3, how do I rename it and get the url?

9 Mar 2016, 3:07 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,099
Plugin Contributions:
56

Re: Need help with a query

If you use page_3, that page's name will (unfortunately) be page_3. That's where the "About Us" page plugin comes in.

That plugin identifies the set of files necessary to create an about_us page and you could use its file structure as a model to create a manufacturers_map page ... or whatever you desire your page to be named.

9 Mar 2016, 3:43 PM
#8
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

OK great. Thank you. Can you take a look at the code he gave me and help modify it to what I am looking for?

http://tacticaloffense.com/store/index.php?main_page=page_3

I need for each letter in the header to move down to the letter of the manufacturers, and then turn the list of manufacturers in to links to product listings for those manufacturers.

Is that something you can help with?

9 Mar 2016, 4:11 PM
#9
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Need help with a query

clint6998:

OK great. Thank you. Can you take a look at the code he gave me and help modify it to what I am looking for?

http://tacticaloffense.com/store/index.php?main_page=page_3

I need for each letter in the header to move down to the letter of the manufacturers, and then turn the list of manufacturers in to links to product listings for those manufacturers.

Is that something you can help with?

Was going to ask if you were okay with the vertical list created or not, looks like not. Are you hard pressed for the horizontal alphabetization or would vertically alphabetized be sufficient? (Obviously ideal would be able to handle both.)

The first part of the provided solution is somewhat browser dependent as it currently uses internal links to shift the page to the selected "letter" but not all browsers (versions within browser) support that unfortunately. As to the manufacturer link being clickable, the information is present in the query and just need to generate a correct link using zen_html_ref as the function to return the formatted link and wrap the manufacturer with the html for a link.

9 Mar 2016, 4:28 PM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Need help with a query

<?php

    for ($i=65; $i<91; $i++) {
    echo '<a href="'.chr($i).'">' . chr($i) . '</a>';
    }
    for ($i=48; $i<58; $i++) {
    echo '<a href="'.chr($i).'">' . chr($i) . '</a>';
    }

echo '<br class="clearBoth" />';


$manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name"; 

$manufacturers = $db->Execute($manufacturers_query);

while (!$manufacturers->EOF) {

    if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) {
        $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1));
        echo '<a name="#'.$initial.'">' . $initial . '</a><br />----------<br />';
    }
    ?><a href="<?php echo zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int) $manufacturers->fields['manufacturers_id'], $request_type); ?>" ><?php echo $manufacturers->fields['manufacturers_name']; ?></a><br /><?php

      $manufacturers->MoveNext();
    }
?>

The above has been modified to add the manufacturer's link using the existing vertical formatting. The click from letter to section remains as was provided.

9 Mar 2016, 5:39 PM
#11
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

mc12345678:

Was going to ask if you were okay with the vertical list created or not, looks like not. Are you hard pressed for the horizontal alphabetization or would vertically alphabetized be sufficient? (Obviously ideal would be able to handle both.)

The first part of the provided solution is somewhat browser dependent as it currently uses internal links to shift the page to the selected "letter" but not all browsers (versions within browser) support that unfortunately. As to the manufacturer link being clickable, the information is present in the query and just need to generate a correct link using zen_html_ref as the function to return the formatted link and wrap the manufacturer with the html for a link.

The vertical link in the header does not show all manufacturers if that is what you are referring to. As for the horizontal use, I would prefer that. I would like it to be able to count the number of manufacturers that start with lets say "A" (35), divide by 3 (11.66), round up (12), and make the three rows consisting of 12,12, and 11. also, I need to separate the each list as the section for letter "B" runs right up against the last listing of "A", and so on.

9 Mar 2016, 5:41 PM
#12
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

Modified code works great except for one thing. Each letter at the top of the page A B C... ends up looking like this:

http://tacticaloffense.com/store/J

instead of moving down the page to the letter "J"

ALso, I would like to ditch the numbers of 0-9 and just replace it with the # sign.

Also, "About Us" plugin works great!!!

http://tacticaloffense.com/store/index.php?main_page=manufacturers_map

is the new page

9 Mar 2016, 6:06 PM
#13
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Need help with a query

I thank @lat9 @mc12345678

Sorry, I kinda threw this together waiting in an airport trying to get back home

The below code will achieve the layout your going for, inherits @mc12345678 manufacturer links and changes the anchor tags to properly "goto" correct location on page.

Removing 0-9 and combining all numeric results will take some additional coding, I literally just walked in my door and will look at it a little more.

I like the website btw, can I ask what influenced your decision in going with bootstrap?

<?php
    echo '<div id="alphanumericWrapper">';
    echo 'Manufacturers ';
    for ($i=65; $i<91; $i++) {
    echo '<a href="'. $_SERVER['REQUEST_URI'] . '#' . chr($i).'">' . chr($i) . '</a>';
    }
    for ($i=48; $i<58; $i++) {
    echo '<a href="'. $_SERVER['REQUEST_URI'] . '#' . chr($i).'">' . chr($i) . '</a>';
    }
    echo '</div>';

echo '<br class="clearBoth" />';


$manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name"; 

$manufacturers = $db->Execute($manufacturers_query);

while (!$manufacturers->EOF) {

    if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) {
        $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1));

        echo '<br class="clearBoth" />';
        echo '<a name="'.$initial.'" class="bold bigger defaultColor">' . $initial . '</a>';
        echo '<br class="clearBoth" />';
    }

echo '<div style="width: 33.3%; float: left;"><a href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int) $manufacturers->fields['manufacturers_id'], $request_type) . '">' . $manufacturers->fields['manufacturers_name'] . '</a></div>';


      $manufacturers->MoveNext();
    }

        echo '<br class="clearBoth" />';
?> 

clint6998:

Modified code works great except for one thing. Each letter at the top of the page A B C... ends up looking like this:

http://tacticaloffense.com/store/J

instead of moving down the page to the letter "J"

ALso, I would like to ditch the numbers of 0-9 and just replace it with the # sign.

Also, "About Us" plugin works great!!!

http://tacticaloffense.com/store/index.php?main_page=manufacturers_map

is the new page

9 Mar 2016, 6:52 PM
#14
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

rbarbour:

I thank @lat9 @mc12345678

Sorry, I kinda threw this together waiting in an airport trying to get back home

The below code will achieve the layout your going for, inherits @mc12345678 manufacturer links and changes the anchor tags to properly "goto" correct location on page.

Removing 0-9 and combining all numeric results will take some additional coding, I literally just walked in my door and will look at it a little more.

I like the website btw, can I ask what influenced your decision in going with bootstrap?

<?php echo '<div id="alphanumericWrapper">'; echo 'Manufacturers '; for ($i=65; $i<91; $i++) { echo '<a href="'. $_SERVER['REQUEST_URI'] . '#' . chr($i).'">' . chr($i) . '</a>'; } for ($i=48; $i<58; $i++) { echo '<a href="'. $_SERVER['REQUEST_URI'] . '#' . chr($i).'">' . chr($i) . '</a>'; } echo '</div>'; echo '<br class="clearBoth" />'; $manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name"; $manufacturers = $db->Execute($manufacturers_query); while (!$manufacturers->EOF) { if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) { $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1)); echo '<br class="clearBoth" />'; echo '<a name="'.$initial.'" class="bold bigger defaultColor">' . $initial . '</a>'; echo '<br class="clearBoth" />'; } echo '<div style="width: 33.3%; float: left;"><a href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int) $manufacturers->fields['manufacturers_id'], $request_type) . '">' . $manufacturers->fields['manufacturers_name'] . '</a></div>'; $manufacturers->MoveNext(); } echo '<br class="clearBoth" />'; ?>

Thank you all for all of your help!!!

Code is almost there but not quite. I still need them broken up by alpha. Right no it just runs them all together.  

Didnt really decide on bootstrap. Had an older site that needed to be updated badly.  it was not responsive and the graphics just werent cutting it for me anymore so I found a clean looking template and I am trying to make it my own.
9 Mar 2016, 7:06 PM
#15
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

If this gives you a better idea of what I am looking for, lets use the above example.

I would like it to be able to count the number of manufacturers that start with lets say "A" (35), divide by 3 (11.66), round up (12), and make three columns consisting of 12,12, and 11. also, I need to separate the each list as the section for letter "B" runs right up against the last listing of "A", and so on.

So I need 4 div tags. first div tag to have the "A" in it with line break or header tag. Divs 2-4 would nest inside div 1 and have a class called "manufacturersList" or something like that. I could then set the css to float divs 2-4 so that as the screen gets smaller, it adapts to the screen size.

Hope this is not too much trouble.

http://tacticaloffense.com/store/index.php?main_page=manufacturers_map

Thanks,

Clint

9 Mar 2016, 7:16 PM
#16
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Need help with a query

That's exactly what the changes I made do.

make sure their is a break before and after alpha character, doesn't look like you copied that part looking at your view source:

        echo '<br class="clearBoth" />';
        echo '<a name="'.$initial.'" class="bold bigger defaultColor">' . $initial . '</a>';
        echo '<br class="clearBoth" />';

clint6998:

If this gives you a better idea of what I am looking for, lets use the above example.

I would like it to be able to count the number of manufacturers that start with lets say "A" (35), divide by 3 (11.66), round up (12), and make three columns consisting of 12,12, and 11. also, I need to separate the each list as the section for letter "B" runs right up against the last listing of "A", and so on.

So I need 4 div tags. first div tag to have the "A" in it with line break or header tag. Divs 2-4 would nest inside div 1 and have a class called "manufacturersList" or something like that. I could then set the css to float divs 2-4 so that as the screen gets smaller, it adapts to the screen size.

Hope this is not too much trouble.

http://tacticaloffense.com/store/index.php?main_page=manufacturers_map

Thanks,

Clint

9 Mar 2016, 7:18 PM
#17
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Need help with a query

Also doesn't look like you added the last break either

      $manufacturers->MoveNext();
    }

        echo '<br class="clearBoth" />';

clint6998:

If this gives you a better idea of what I am looking for, lets use the above example.

I would like it to be able to count the number of manufacturers that start with lets say "A" (35), divide by 3 (11.66), round up (12), and make three columns consisting of 12,12, and 11. also, I need to separate the each list as the section for letter "B" runs right up against the last listing of "A", and so on.

So I need 4 div tags. first div tag to have the "A" in it with line break or header tag. Divs 2-4 would nest inside div 1 and have a class called "manufacturersList" or something like that. I could then set the css to float divs 2-4 so that as the screen gets smaller, it adapts to the screen size.

Hope this is not too much trouble.

http://tacticaloffense.com/store/index.php?main_page=manufacturers_map

Thanks,

Clint

9 Mar 2016, 7:29 PM
#18
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

rbarbour:

Also doesn't look like you added the last break either

  $manufacturers->MoveNext();
}

    echo '<br class="clearBoth" />';

Its all there. Here is what I have in the define editor:

```php
<?php 
    echo '<div id="alphanumericWrapper">'; 
    echo 'Manufacturers '; 
    for ($i=65; $i<91; $i++) { 
    echo '<a href="'. $_SERVER['REQUEST_URI'] . '#' . chr($i).'">' . chr($i) . '</a>'; 
    } 
    for ($i=48; $i<58; $i++) { 
    echo '<a href="'. $_SERVER['REQUEST_URI'] . '#' . chr($i).'">' . chr($i) . '</a>'; 
    } 
    echo '</div>'; 

echo '<br class="clearBoth" />'; 


$manufacturers_query = "SELECT distinct manufacturers_id, manufacturers_name FROM " . TABLE_MANUFACTURERS . " ORDER BY manufacturers_name";  

$manufacturers = $db->Execute($manufacturers_query); 

while (!$manufacturers->EOF) { 

    if ($initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1))) { 
        $initial = strtoupper(substr($manufacturers->fields['manufacturers_name'], 0, 1)); 

        echo '<br class="clearBoth" />'; 
        echo '<a name="'.$initial.'" class="bold bigger defaultColor">' . $initial . '</a>'; 
        echo '<br class="clearBoth" />'; 
    } 

echo '<div style="width: 33.3%; float: left;"><a href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int) $manufacturers->fields['manufacturers_id'], $request_type) . '">' . $manufacturers->fields['manufacturers_name'] . '</a></div>'; 


      $manufacturers->MoveNext(); 
    } 

        echo '<br class="clearBoth" />'; 
?>
9 Mar 2016, 11:32 PM
#19
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: Need help with a query

It works perfectly in a vanilla install.

The beauty of foundation and bootstrap frameworks, don't think anyone realizes how bad they effect things.

I added the following CSS to achieve the same look on your site. Adding classes would help clean it up a little but I really don't think it's gonna matter for bootstraps CSS files are so large anyways.

Sorry, just ranting.

div#alphanumericWrapper { width:100%; margin: 1em; }
div#alphanumericWrapper a{ padding: 0 0.2em; }
a.bold.bigger.defaultColor { display:block; clear:both; color:#000;font-weight:bold; }
div#manufacturers_map.centerColumn>div { display:inline-block; clear:both; } 
10 Mar 2016, 2:49 AM
#20
clint6998 avatar

clint6998

Zen Follower

Join Date:
Aug 2012
Posts:
106
Plugin Contributions:
0

Re: Need help with a query

rbarbour:

It works perfectly in a vanilla install.

The beauty of foundation and bootstrap frameworks, don't think anyone realizes how bad they effect things.

I added the following CSS to achieve the same look on your site. Adding classes would help clean it up a little but I really don't think it's gonna matter for bootstraps CSS files are so large anyways.

Sorry, just ranting.

div#alphanumericWrapper { width:100%; margin: 1em; }
div#alphanumericWrapper a{ padding: 0 0.2em; }
a.bold.bigger.defaultColor { display:block; clear:both; color:#000;font-weight:bold; }
div#manufacturers_map.centerColumn>div { display:inline-block; clear:both; }


Looks pretty good after the css. Might need just a little more tweaking of it. I do have one concern though.  When you click a letter, it does go down to it as it should, however, it removes everything above it so you can't scroll back up.  ANy ideas on that?

Thanks,

Clint