Skip to content

Instantly share code, notes, and snippets.

@avinashdexterous
Forked from tchalvak/belts_example.php
Created December 20, 2012 14:39
Show Gist options
  • Select an option

  • Save avinashdexterous/4345638 to your computer and use it in GitHub Desktop.

Select an option

Save avinashdexterous/4345638 to your computer and use it in GitHub Desktop.

Revisions

  1. avinashdexterous revised this gist Dec 20, 2012. 1 changed file with 37 additions and 3 deletions.
    40 changes: 37 additions & 3 deletions belts_example.php
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,42 @@
    db.php
    ======
    <?php

    $USER_NAME = "test";
    $USER_PWD = "test";
    $MYSQL_HOST= "test";
    $DATABASE = "test";

    $dbLink = mysql_connect( $MYSQL_HOST, $USER_NAME, $USER_PWD );
    mysql_select_db($DATABASE, $dbLink) or die( "Unable to select database..." );
    }
    ?>
    model.php
    =========
    <?php
    class Model(){
    var $dbLink;
    function Model($dbLink){
    $this->dbLink=$dbLink;
    }
    function fetchRecords(){
    $qry="SELECT brands.Code, brands.Name as BrandName, brands.DescrShort, brands.LogoURL FROM types, items, brands WHERE BrandName NOT LIKE '%Belt%' AND types.Name NOT LIKE '%Belt%' AND types.TypeId = items.TypeId AND items.BrandCode = brands.Code AND items.flagStatus != 'U' GROUP BY brands.Code ORDER BY brands.Name";
    $results=mysql_query($qry, $this->dbLink);
    return $results;
    }
    }
    ?>

    belt_example.php
    ================

    <?php
    session_start();
    include_once("db.php");
    include_once("model.php");

    // TODO: Fix this so that it doesn't require "Belt" to be in the name.
    $belt_brands = query("SELECT brands.Code, brands.Name as BrandName, brands.DescrShort, brands.LogoURL FROM types, items, brands WHERE types.Name LIKE '%Belt%' AND types.TypeId = items.TypeId AND items.BrandCode = brands.Code AND items.flagStatus != 'U' GROUP BY brands.Code ORDER BY brands.Name");
    $obj=new Model();
    $belt_brands = $obj->fetchRecords();

    $Title = 'Belts';
    $with_footer = false;
    @@ -65,4 +99,4 @@
    ?>
    <?php
    include('includes/footer.php');
    ?>
    ?>
  2. @tchalvak tchalvak created this gist Jun 10, 2012.
    68 changes: 68 additions & 0 deletions belts_example.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    <?php
    session_start();

    // TODO: Fix this so that it doesn't require "Belt" to be in the name.
    $belt_brands = query("SELECT brands.Code, brands.Name as BrandName, brands.DescrShort, brands.LogoURL FROM types, items, brands WHERE types.Name LIKE '%Belt%' AND types.TypeId = items.TypeId AND items.BrandCode = brands.Code AND items.flagStatus != 'U' GROUP BY brands.Code ORDER BY brands.Name");

    $Title = 'Belts';
    $with_footer = false;
    include('heading.php');
    ?>

    <?php

    display_top_of_page($breadcrumbs=null, $dynamic_breadcrumbs=null, $page_class='belts-page'); // includes leftnav, the start of the central column td that has a background color of #ffffff, and possibly a breadcrumb trail, END.


    display_starting_cell('belts-start');
    ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-left:5px">
    <tr><td>



    <h1 class='fancy-nothing-font page-title'>Belts</h1></td></tr>
    <tr>
    <td>Click on any of the links below to shop our belt collections by brand or browse <a href="catalog.php?TypeId=1">All Premium Belt Collections</a>.</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    <?php
    foreach ($belt_brands as $belt_brand) {
    ?>
    <div class='belt-brand' style='margin-top:0;margin-bottom:.3em;'>
    <h3 style="padding:5px;background:#99a4de; border-top:1px solid #000000; border-bottom:1px solid #000000;font-weight:bold" class='belt-brand-name brand-name'>
    <?php h($belt_brand['BrandName']); ?>
    </h3>

    <div class='brand-desc' style='padding:5px'>
    <a href="catalog.php?TypeId=1&amp;TypeBrandCode=<?php h($belt_brand['Code']); ?>">
    <img src="assets/belt-<?php h($belt_brand['LogoURL']); ?>"
    width='150' border="0" align="right" style="padding:5px; margin-left:5px; border:1px solid #cccccc"
    alt="<?php h($belt_brand['BrandName']); ?> Belts"
    title="<?php h($belt_brand['BrandName']); ?> Belts">
    </a>
    <div class='short-brand-description'>
    <?php echo $belt_brand['DescrShort']; // Uses unescaped html, sadly ?>
    </div>
    </div>

    <div class='shop-belts' style='width:100%;text-align:center;font-size:1.1em;font-weight:bold;clear:both;'>
    [ <a class='shop-belts-link' href="catalog.php?TypeId=1&amp;TypeBrandCode=<?php echo $belt_brand['Code']; ?>">
    Shop <?php h($belt_brand['BrandName']); ?> Belts</a> ]
    </div>


    </div> <!-- End of a belt brand -->

    <?php } // End of belt_brands loop
    ?>

    <?php
    display_bottom_of_page(); // Ends a td, ends a tr, and ends a table (with page elements for right-side-nav-container, right and bottom shadow inbetween)
    ?>
    <?php
    include('includes/footer.php');
    ?>