Page 4 of 4 FirstFirst ... 234
Results 31 to 36 of 36
  1. #31
    Join Date
    Sep 2008
    Posts
    210
    Plugin Contributions
    21

    Default Re: Need help with a query

    Quote Originally Posted by clint6998 View Post
    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
    When you see the same question, you only should discuss about the idea how to do, don't help them to do it because it is not good for them :)

    Regarding this question, this is my idea:

    1. Query all manufacturers.
    2. Create an array and detect the first character.
    3. If the manufacturer name has the first character, push it into array.

    Code:
    $array['A'] = array('A Brand', 'AB brand');
    $array['B'] = array('B Brand', 'BB brand');
    4. Loop and show it.
    Our Site: http://zucando.com
    Marketing Plugins: Marketing Modules
    Free Response Templates: Responsive Templates

  2. #32
    Join Date
    Aug 2012
    Posts
    106
    Plugin Contributions
    0

    Default Re: Need help with a query

    Quote Originally Posted by cvhainb View Post
    When you see the same question, you only should discuss about the idea how to do, don't help them to do it because it is not good for them :)

    Regarding this question, this is my idea:

    1. Query all manufacturers.
    2. Create an array and detect the first character.
    3. If the manufacturer name has the first character, push it into array.

    Code:
    $array['A'] = array('A Brand', 'AB brand');
    $array['B'] = array('B Brand', 'BB brand');
    4. Loop and show it.
    Is this not a community? Communities help each other. You say it is not good for coders to help write for someone in need? Its because of people like the ones who have helped me and others that bring ideas to life and help bet peoples sites online. I know how to drive a car but I am no mechanic. Talking to people on a forum would not get my car fixed unless someone told me exactly what was wrong and how to fix it. Otherwise I would have to take it to a mechanic. Thank you for your input and code, but this issue has already been resolved with many thanks to the few people who contributed in writing the code for me.

  3. #33
    Join Date
    Nov 2007
    Location
    Woodbine, Georgia, United States
    Posts
    4,035
    Plugin Contributions
    61

    Default Re: Need help with a query

    Would be incredibly simpler to use link anchors to a div for each letter and maybe a little javascript affect.

    Found a simple tutorial, below, saved a ton of typing =)

    1.) Name the Target
    Choose the exact spot you want to send your link to, choose and element near it (a div, header tag, paragraph.. whatever as long as it's in the right spot), add id="something", you can call them anything you like as long as the names are the same in the link and the target ID and preferably no spaces (spaces change to %20 in the address bar and look a tad messy).

    An example would look like this:
    <div id="whatever-you-want-to-call-it">
    The content of your div here.
    </div>

    2.) Link To Your Anchor Target
    To link to your anchor simply use:
    <a href="#whatever-you-want-to-call-it">Link Text Here</a>

    or if it's on another page:
    <a href="pagename.html#whatever-you-want-to-call-it">Link Text Here</a>
    Sometimes simpler is far better,

    ~Melanie
    PRO-Webs, Inc. :: Recent Zen Cart Projects :: Zen Cart SEO – 12 Steps to Success
    **I answer questions in the forum, private messages are NOT answered. You are welcome to contact us via our website for professional engagements.

  4. #34
    Join Date
    Jul 2012
    Posts
    16,740
    Plugin Contributions
    17

    Default Re: Need help with a query

    Quote Originally Posted by mprough View Post
    Would be incredibly simpler to use link anchors to a div for each letter and maybe a little javascript affect.

    Found a simple tutorial, below, saved a ton of typing =)



    Sometimes simpler is far better,

    ~Melanie
    Not sure what ton of typing is being saved, the solution that was previously provided used a very similar approach allowing/using ascii character codes as the link identifier (modifiable to whatever value/span desired) and the list of items was/is generated from live store data which therefore could then be used on any such store and would change on the fly rather than having to be "maintained". Looking at the end result, although there was php code support needed to get the process done, there has been other web effects added.

    I mean if there was anything I might change about the provided code would be that the header list would exclude letters that are not to be found in the below list. At the same time if a company say in Germany has an umlauted first letter, it will not show up properly in the list as it doesn't start with one of the prescribed letters and not a number... But, overall it's a robust solution for the vast majority of situations and relatively easy to maintain. The worst case by not having the above "change", is that there isn't a letter on which to click to go to the applicable company grouping, but the company (manufacturer) is still listed.

    As to providing code versus pseudo code, yeah, time and place. But someone had some kick back time while hanging out waiting for a flight and an interest to write some code.... Helped a zenner out, maybe they learned something from it and might apply it to something else in the future, maybe more ideas will come forth.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #35
    Join Date
    Mar 2016
    Posts
    14
    Plugin Contributions
    0

    Default Re: Need help with a query

    Quote Originally Posted by clint6998 View Post
    ok so I have made a few changes to the page and css. Here is the new php and a screen shot as it seems that in a the listings are in teh following order:

    div-->manufacturers-->clearBoth-->Next alpha-->attop link. Any ideas? See image below php

    PHP Code:
    <?php 
        
    echo '<div id="alphanumericWrapper"><span class="buttonRow btn"><div style="float: left; padding: 0;margin:4,0"><a name="attop">'
        echo 
    '<a href="'$_SERVER['REQUEST_URI'] . '#hash">#</a></div>';
        for (
    $i=65$i<91$i++) {
        echo 
    '<div style="float: left; padding: 0;margin:4,0"><a href="'$_SERVER['REQUEST_URI'] . '#' chr($i).'">' chr($i) . '</a></div>'
        }
        echo 
    '</span></div>'

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


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

    $manufacturers $db->Execute($manufacturers_query); 
    $numeric_displayed false;

    while (!
    $manufacturers->EOF) { 

        if (!
    is_numeric(strtoupper(substr($manufacturers->fields['manufacturers_name'], 01))) && $initial !== strtoupper(substr($manufacturers->fields['manufacturers_name'], 01))) { 
            
    $initial strtoupper(substr($manufacturers->fields['manufacturers_name'], 01)); 
            echo 
    '<br class="clearBoth" /><br class="clearBoth" />'
            echo 
    '<h4 class="manufacturers" style="width: 100%"><a name="'.$initial.'" class="bold bigger defaultColor">' $initial '</a><span style="align: right;" class="btn buttonRow"><a href="'.$_SERVER['REQUEST_URI'] . '#attop">Back to Top</a></span></h4>'
           

            echo 
    '<br class="clearBoth" /><br class="clearBoth" />'
        } elseif (!
    $numeric_displayed && is_numeric(strtoupper(substr($manufacturers->fields['manufacturers_name'], 01)))) {
             
    $initial strtoupper(substr($manufacturers->fields['manufacturers_name'], 01));

             echo 
    '<br class="clearBoth" />';
             echo 
    '<h4 class="manufacturers" style="width: 100%"><a name="hash" class="bold bigger defaultColor">#</a>';
             echo 
    '##<span style="align: right;" class="btn buttonRow"><a href="'.$_SERVER['REQUEST_URI'] . '#attop">Back to Top</a></span></h4>';
             echo 
    '<br class="clearBoth" />';
             
    $numeric_displayed true;
         }

    echo 
    '<div style="width: 33.3%; float: left; min-width:200px"><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" />'
    ?>
    screenshot
    Attachment 16095
    I agree with @cvhainb, and I have some suggestion for you:

    PHP Code:
    <?php
    // manufacturers map page
    // includes/modules/pages/manufacturers_map/header_php.php
    // template: includes/templates/YOUR_TEMPLATE/templates/tpl_manufacturers_map_default.php
    // store manufacturers in array
    $number_list $manufacturers_list = array();
    $letter_list range('A''Z');
    $manufacturers_map_title 'Manufacturers Map';
    $link_format '<li><a href="%s%s" target="_self">%s</a></li>';
    $manufacturers_map_link zen_href_link('manufacturers_map');
    $manufacturers_mid_link zen_href_link(FILENAME_DEFAULT'manufacturers_id=%d');
    $breadcrumb->add($manufacturers_map_title);
    define(META_TAG_TITLE$manufacturers_map_title PRIMARY_SECTION TITLE);
    // fetch all manufacturers from db
    // ORDER BY usually cause low performance problem, using PHP sort instead
    $manufacturers_list_get $db->Execute(sprintf('SELECT manufacturers_id, manufacturers_name FROM `%s`;'TABLE_MANUFACTURERS));
    while (!
    $manufacturers_list_get->EOF) {
      
    $manufacturers_name ucwords(trim($manufacturers_list_get->fields['manufacturers_name']));
      
    $first_letter substr($manufacturers_name01);
      
    // check if number
      
    if (is_numeric($first_letter)) {
        
    $number_list[] = array('name' => $manufacturers_name'id' => $manufacturers_list_get->fields['manufacturers_id']);
      }else{
        
    // check if duplicate
        
    if (!isset($manufacturers_list[$first_letter][$manufacturers_name])) {
          
    $manufacturers_list[$first_letter][$manufacturers_name] = $manufacturers_list_get->fields['manufacturers_id'];
        }
      }
      
    $manufacturers_list_get->MoveNext();
    }
    // now we can show manufacuters list in includes/templates/YOUR_TEMPLATE/templates/tpl_manufacturers_map_default.php
    //EOF
    template: includes/templates/YOUR_TEMPLATE/templates/tpl_manufacturers_map_default.php
    PHP Code:
    <style>
      .clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}
      .clearfix{*+height:1%;}
      #manufacturers_map{}
      #manufacturers_letter ul{list-style: none;}
      #manufacturers_letter ul li{border-right: 1px solid #aaa; float: left; margin: 0;}
      #manufacturers_letter ul li:last-child{border: none;}
      #manufacturers_letter ul li a{display: inline-block; padding: 0 5px;}
      .manufacturers_list{margin: 15px 0;}
      .manufacturers_list .letter{margin-top: 10px;}
      .manufacturers_list .letter h3{display: inline-block;}
      .manufacturers_list .letter span{float: right;}
      .manufacturers_list .letter span a{color: #aaa}
      .manufacturers_list .list{list-style: none; border-top: 1px solid #aaa;}
      .manufacturers_list .list li{float: left; width: 33%}
    </style>
    <div id="manufacturers_map">
      <h1><?php echo $manufacturers_map_title;?></h1>
      <div id="manufacturers_letter">
        <ul class="clearfix">
        <?php
          
    echo sprintf($link_format$manufacturers_map_link"#hash"'#');
          foreach (
    $letter_list as $letter) {
            echo 
    sprintf($link_format$manufacturers_map_link"#$letter"$letter);
          }
        
    ?>
        </ul>
      </div>
      <?php
        $block 
    '<div class="manufacturers_list"><div class="letter clearfix"><h3><a name="%s"></a>%s</h3><span><a href="%s#">top</a></span></div><ul class="list clearfix">%s</ul></div>';
        if (!empty(
    $number_list)) {
          
    $links = array();
          foreach (
    $number_list as $num_item) {
            
    $links[] = sprintf($link_formatsprintf($manufacturers_mid_link$num_item['id']), ''$num_item['name']);
          }
          echo 
    sprintf($block'hash''#'$manufacturers_map_linkimplode(''$links));
        }
        foreach (
    $letter_list as $letter) {
          if (isset(
    $manufacturers_list[$letter])) {
            
    $block_data sprintf($block$letter$letter$manufacturers_map_link'%s');
            
    $links = array();
            foreach (
    $manufacturers_list[$letter] as $m_name => $m_id) {
              
    $links[] = sprintf($link_formatsprintf($manufacturers_mid_link$m_id), ''$m_name);
            }
            
    $block_data sprintf($block_dataimplode(''$links));
            echo 
    $block_data;
          }
        }
      
    ?>
    </div>

  6. #36
    Join Date
    Jul 2012
    Posts
    16,740
    Plugin Contributions
    17

    Default Re: Need help with a query

    A few things,
    1) Doesn't address one of the requirements of the OP, businesses that begin with a non letter first of all are not even considered in this listing let alone grouped into a single choice.
    2) Doesn't even present businesses that don't begin with anything but a letter between a and z.
    3) Styling is all within one of the files instead of in a stylesheet which would get loaded. See the help file in: includes/templates/template_default/css
    4) Capitalization is forced into a first letter of each word rather than as entered (which should reflect the captalization carried by the business itself).
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  2. Need help creating SQL query...
    By DigitalShadow in forum General Questions
    Replies: 2
    Last Post: 22 Jun 2011, 02:05 PM
  3. Need help with a mySQL Query
    By jeffmic in forum General Questions
    Replies: 3
    Last Post: 19 Dec 2010, 02:21 PM
  4. Need help with SQL query. Want to make membership that expires.
    By TecBrat in forum Managing Customers and Orders
    Replies: 1
    Last Post: 18 Jun 2010, 03:43 PM
  5. Need help w/ SQL query in phpMyAdmin
    By audradh in forum General Questions
    Replies: 17
    Last Post: 16 Nov 2009, 01:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR