Thread: SQL question

Page 3 of 7 FirstFirst 12345 ... LastLast
Results 21 to 30 of 68
  1. #21
    Join Date
    Feb 2010
    Posts
    3
    Plugin Contributions
    0

    Default Re: SQL question

    SQL ----

    $unique_model = $db->Execute("SELECT DISTINCT products_model FROM products");

    Display ----

    while (!$unique_model->EOF) {
    echo $unique_model->fields['products_model'];
    $unique_model->MoveNext();
    }

    This will echo out the names as long as your query is bringing back the distinct values. You can also add code to it such as links. To setup the correct reference you may have to build a more complex query.

    Example:

    echo '<a href="link code" alt="alt name" />'.$unique_model->fields['products_model'].'</a>';

  2. #22
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    hitmike could you help build that for me, as that is exactly what i am looking to do.

    Have the generated list become clickable and result in each item searching the shop... you follow?

  3. #23
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    yay! Thank you all

    <?php

    $unique_model = $db->Execute("SELECT DISTINCT products_model_number FROM `zen_products_description`ORDER BY products_model_number ASC");

    while (!$unique_model->EOF) {
    echo '<a href="http://website-here.com/index.php?main_page=advanced_search_result&search_in_description=1&keyword='.$un ique_model->fields['products_model_number'].'" alt="alt name" />'.$unique_model->fields['products_model_number'].'</a><br />';
    $unique_model->MoveNext();
    }

    ?>

  4. #24
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    Ok one last question, how would I get the above code to only show results from one manufactuers_id? something using left join?

    manufactuers_id is in zen_products and products_model_number is in zen_products_description

  5. #25
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    Done it

    <?php

    $unique_model = $db->Execute("SELECT DISTINCT pd.products_model_number, p.manufacturers_id FROM " . TABLE_PRODUCTS_DESCRIPTION . " pd LEFT JOIN " . TABLE_PRODUCTS . " p ON pd.products_id = p.products_id WHERE p.manufacturers_id = '2' ORDER BY pd.products_model_number ASC");

    while (!$unique_model->EOF) {
    echo '<a href="http://webdomain.com/index.php?main_page=advanced_search_result&search_in_description=1&keyword='.$un ique_model->fields['products_model_number'].'" alt="alt name" />'.$unique_model->fields['products_model_number'].'</a><br />';
    $unique_model->MoveNext();
    }

    ?>
    Last edited by DigitalShadow; 15 Nov 2010 at 11:22 PM.

  6. #26
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    Deleted post...
    Last edited by DigitalShadow; 15 Nov 2010 at 11:35 PM.

  7. #27
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    Is it possible to go through each manufacturers_id one by one and generate a different list each time without me having to have separate php statements for each manufacturers_id?

    <?php

    $manufacturers = $db->Execute("SELECT manufacturers_name FROM zen_manufacturers WHERE manufacturers_id = '2'");
    $unique_model = $db->Execute("SELECT DISTINCT pd.products_model_number, p.manufacturers_id FROM " . TABLE_PRODUCTS_DESCRIPTION . " pd LEFT JOIN " . TABLE_PRODUCTS . " p ON pd.products_id = p.products_id WHERE p.manufacturers_id = '2' ORDER BY pd.products_model_number ASC");

    echo $manufacturers->fields['manufacturers_name'];

    while (!$unique_model->EOF) {
    echo '<a href="http://webdomain.com/index.php?main_page=advanced_search_result&search_in_description=1&keyword='.$un ique_model->fields['products_model_number'].'" alt="alt name" />'.$unique_model->fields['products_model_number'].'</a><br />';
    $unique_model->MoveNext();
    }

    ?>

  8. #28
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    The generated list is quite long even when split into the different manufacturers, what I want to know is it possible to make the generated list split into different div columns? Is it possible to get the outputted list to spread itself across 4 div columns?

    I'm using the following code

    Code:
    <?php
    $manufacturers1 = $db->Execute("SELECT manufacturers_name FROM zen_manufacturers WHERE manufacturers_id = '1'");
    $unique_model1 = $db->Execute("SELECT DISTINCT pd.products_model_number, p.manufacturers_id FROM " . TABLE_PRODUCTS_DESCRIPTION . " pd LEFT JOIN " . TABLE_PRODUCTS . " p ON pd.products_id = p.products_id WHERE p.manufacturers_id = '1' ORDER BY pd.products_model_number ASC");
    ?>
    
    <?php echo '<h3>'.$manufacturers1->fields['manufacturers_name'].' Some text here:</h3>'; ?> 
    <ul id="list" class="model-list">
    
    <?php
    echo "<br /><br />";
    while (!$unique_model1->EOF) {
    echo '<li class="list-item"><a href="http://webdomain.co.uk/index.php?main_page=advanced_search_result&search_in_description=1&keyword='.$unique_model1->fields['products_model_number'].'" alt="alt name" /><font color="#0099cc">'.$unique_model1->fields['products_model_number'].'</font></a></li>' . "\n";
    $unique_model1->MoveNext();
    }
    ?>
    
    </ul>

  9. #29
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    any ideas?

  10. #30
    Join Date
    Mar 2009
    Posts
    609
    Plugin Contributions
    0

    Default Re: SQL question

    So to recap my last two requests are to have the php script generate separate lists for each of the manufacturers_id, i.e. start at "1" and end at the last number

    Other request is to have the outputted list spread itself across four columns automatically. Just need it to after "x" results place a </div> and then start a new <div> for a new column.

    Also would be nice if the first request could then be sorted alphabetically by the manufacturers name "ORDER BY manufacturers_name ASC"

 

 
Page 3 of 7 FirstFirst 12345 ... LastLast

Similar Threads

  1. v154 SQL Script Question
    By Feznizzle in forum General Questions
    Replies: 2
    Last Post: 2 Jul 2015, 07:13 PM
  2. SQL question
    By timhersh in forum General Questions
    Replies: 14
    Last Post: 1 Oct 2012, 10:12 PM
  3. SQL question
    By pixelpadre in forum General Questions
    Replies: 9
    Last Post: 26 Apr 2012, 02:14 PM
  4. v139h SQL question... help please!
    By Feznizzle in forum General Questions
    Replies: 4
    Last Post: 3 Mar 2012, 10:31 PM
  5. SQL Question Deleting zones
    By kitcorsa in forum General Questions
    Replies: 2
    Last Post: 12 May 2008, 12:37 PM

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