Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: please help getting content from db to display in vertical 'columns' with in a div!

  1. #1
    Senior Member ljackson's Avatar
    Join Date
    Feb 2009
    Posts
    570

    Post please help getting content from db to display in vertical 'columns' with in a div! 1 May 2011 @ 20.43

    Hi All,

    im really stuck, i have a menu which when you hover over the menu items a drop down box appears, which is great, and im in the process of adding data to these drop downs, 'discount codes' to be specific, you will notice when you hover over discount codes a list of stores appear grouped by letter.

    now the trouble im having is that i want the stores to appear as they are 'one under another' but instead of continuing outside of the div create a new 'column' inside and carry on so it woul look something like this

    a f k p u
    b g l q v
    c h m r w
    d i n s x
    e j o t y
    z

    and not
    a b c d e f
    g h i j k l m
    n o p q r s
    t u v w x y z

    any ideas how this can be acheived pref just using css

    many thanks
      Reply With Quote

  2. #2
    Senior Member ljackson's Avatar
    Join Date
    Feb 2009
    Posts
    570

    Default 1 May 2011 @ 23.30

    ok i've kinda solved it but it means doing a lot more work than necessary, i have copied the same piece of coe several imes to show just a certain number of stores like so

    PHP Code:
        <li class="menu_right"><a href="#" class="drop">Discount Codes</a><!-- Begin 3 columns Item -->
        
        <div class="dropdown_3columns align_right"><!-- Begin 3 columns container -->
        <?php
        mysql_query
    ("SET NAMES 'utf8'");

        
    $query mysql_query("SELECT UPPER(SUBSTRING(stores.storeName,1,1)) 
        AS letter, storeID, storeName, rating 
        FROM stores ORDER BY storename ASC"
    )or die(mysql_error());

        while (
    $records = @mysql_fetch_array ($query))
        {
            
    $alpha[$records['letter']] = !isset($alpha[$records['letter']]) ? $alpha[$records['letter']] + 1;
            ${
    $records['letter']}[$records['storeID']] = $records['storeName'];
        }
            
            
        echo 
    "<ul>";
        
        
    // Create Alpha link Listing;
        
    foreach(range('A','E') as $i)
        {
            if (
    array_key_exists ("$i"$alpha))
            {
                
    $count 1;
                echo 
    "<li>";
                echo 
    "<b>".$i."</b><br />";
                foreach ($
    $i as $key=>$value)
                {
                    
    $stores "SELECT *
                    FROM stores 
                    WHERE storeID = '
    $key'";
                    
    $query  mysql_query($stores);?>
                    <?php
                    
    while ($row mysql_fetch_array($query))
                    {
                        
    $name $row['name'];
                        
    $storename trim(htmlspecialchars($row['storeName']));
                        
    $ids $row['storeID'];
                        
    $link htmlspecialchars($row['storeLink']);?>
                        <a href='<?php echo $link?>'><?php echo $storename.", ";?></a><?php
                        $count
    ++;
                    }
                }
                    echo 
    "</li>";
            }
            
    #echo "</ul>";
        
    }
        echo 
    "</ul>";
        
        echo 
    "<ul>";
        
        
    // Create Alpha link Listing;
        
    foreach(range('F','L') as $i)
        {
            if (
    array_key_exists ("$i"$alpha))
            {
                
    $count 1;
                echo 
    "<li>";
                echo 
    "<b>".$i."</b><br />";
                foreach ($
    $i as $key=>$value)
                {
                    
    $stores "SELECT *
                    FROM stores 
                    WHERE storeID = '
    $key'";
                    
    $query  mysql_query($stores);?>
                    <?php
                    
    while ($row mysql_fetch_array($query))
                    {
                        
    $name $row['name'];
                        
    $storename trim(htmlspecialchars($row['storeName']));
                        
    $ids $row['storeID'];
                        
    $link htmlspecialchars($row['storeLink']);?>
                        <a href='<?php echo $link?>'><?php echo $storename.", ";?></a><?php
                        $count
    ++;
                    }
                }
                    echo 
    "</li>";
            }
            
    #echo "</ul>";
        
    }
        echo 
    "</ul>";

        echo 
    "<ul>";
        
        
    // Create Alpha link Listing;
        
    foreach(range('M','R') as $i)
        {
            if (
    array_key_exists ("$i"$alpha))
            {
                
    $count 1;
                echo 
    "<li>";
                echo 
    "<b>".$i."</b><br />";
                foreach ($
    $i as $key=>$value)
                {
                    
    $stores "SELECT *
                    FROM stores 
                    WHERE storeID = '
    $key'";
                    
    $query  mysql_query($stores);?>
                    <?php
                    
    while ($row mysql_fetch_array($query))
                    {
                        
    $name $row['name'];
                        
    $storename trim(htmlspecialchars($row['storeName']));
                        
    $ids $row['storeID'];
                        
    $link htmlspecialchars($row['storeLink']);?>
                        <a href='<?php echo $link?>'><?php echo $storename.", ";?></a><?php
                        $count
    ++;
                    }
                }
                    echo 
    "</li>";
            }
            
    #echo "</ul>";
        
    }
        echo 
    "</ul>";

        echo 
    "<ul>";
        
        
    // Create Alpha link Listing;
        
    foreach(range('S','Z') as $i)
        {
            if (
    array_key_exists ("$i"$alpha))
            {
                
    $count 1;
                echo 
    "<li>";
                echo 
    "<b>".$i."</b><br />";
                foreach ($
    $i as $key=>$value)
                {
                    
    $stores "SELECT *
                    FROM stores 
                    WHERE storeID = '
    $key'";
                    
    $query  mysql_query($stores);?>
                    <?php
                    
    while ($row mysql_fetch_array($query))
                    {
                        
    $name $row['name'];
                        
    $storename trim(htmlspecialchars($row['storeName']));
                        
    $ids $row['storeID'];
                        
    $link htmlspecialchars($row['storeLink']);?>
                        <a href='<?php echo $link?>'><?php echo $storename.", ";?></a><?php
                        $count
    ++;
                    }
                }
                    echo 
    "</li>";
            }
            
    #echo "</ul>";
        
    }
        echo 
    "</ul>";
        
    ?>
        </div><!-- End 3 columns container -->
        
        </li><!-- End 3 columns Item -->
    but i would like to condense this if at all possible, or if there is a better way to do this please share
    thanks
      Reply With Quote

  3. #3
    Administrator WelshStew's Avatar
    Join Date
    Dec 2008
    Posts
    2,969
    Blog Entries
    3

    Default 3 May 2011 @ 08.12

    From a UI perspective, people read left to right (in the western world), therefore it would be better usability to have it output like the second example.

    Confusing people will result in a lower conversion / CTR.

    [edit]
    Ignore me, I have just seen what you are trying to achieve under the retail stores tab and it does work better like you want it to above.
      Reply With Quote

  4. #4
    Member janvt's Avatar
    Join Date
    Jan 2011
    Posts
    182

    Default 3 May 2011 @ 10.15

    well, for starters, you could slap your repeated foreach loops in a function with the range as parameters:

    PHP Code:

    output_stores
    ('A','E',$alpha);
    ...
    output_stores('F','L',$alpha);

    function 
    output_stores($from,$to,$alpha)
    {
      foreach(
    range($from,$to) as $i)
      {
          if (
    array_key_exists ("$i"$alpha))
          {
              
    $count 1;
      .....

    Last edited by janvt; 3 May 2011 at @ 10.17.
      Reply With Quote

  5. #5
    Senior Member ljackson's Avatar
    Join Date
    Feb 2009
    Posts
    570

    Default 4 May 2011 @ 13.02

    @welshstew - i would be easier from a coding point of view as well because floats float left or right not up and down which is a real pain as ive had to hard code it as i cannot get them to automatically flow down and then across, which looks a little untidy because i dont know which stores have codes and how many - the joys of codeing :D

    @janvt
    thanks mate didnt even think of that
    ive condensed it like so
    PHP Code:
            output_stores('A','C',$alpha);
            output_stores('D','J',$alpha);
            output_stores('K','Q',$alpha);        
            output_stores('R','Z',$alpha);
            
            function output_stores($from,$to,$alpha)
            {
                $getcodes = mysql_query("SELECT  UPPER(SUBSTRING(stores.storeName,1,1)) AS letter, storeID, storeName,  rating FROM stores ORDER BY storename ASC")
                or die(mysql_error());
                while ($records = @mysql_fetch_array ($getcodes))
                {
                    $alpha[$records['letter']] = !isset($alpha[$records['letter']]) ? 1 : $alpha[$records['letter']] + 1;
                    ${$records['letter']}[$records['storeID']] = $records['storeName'];
                }        
                echo "<ul>";
                // Create Data Listing
                foreach(range($from,$to) as $i)
                {
                    if (array_key_exists ("$i", $alpha))
                    {
                        foreach ($$i as $key=>$value)
                        {
                            $checkcodes = mysql_query("SELECT codeID,code,codeLink,storeID,details,expireDate
                            FROM tbl_codes  
                            WHERE storeID = '$key'
                            ORDER BY expireDate ASC")or die(mysql_error);
                            $rows = mysql_num_rows($checkcodes);
                            if($rows >=1)
                            {
                                echo "<li>";
                                $code_count = 1;
                                //GET STORE LINK
                                $sql = mysql_query("SELECT * FROM stores WHERE name = '$value'")or die(mysql_error());
                                $row = mysql_fetch_array($sql);
                                $link = htmlentities($row['storeLink']);
                            
                                echo "<b>".htmlspecialchars($value)?></b><br /><?php
                                
    while ($row mysql_fetch_array($checkcodes))
                                {
                                    
    $codeLink htmlspecialchars($row['codeLink']);?>                            
                                    <a href="<?php echo  $codeLink?>" title="<?php echo $row['details']?>"><?php  echo $row['code']?></a><?php
                                    
    if($code_count <> $rows)
                                    {
                                        echo 
    ", ";
                                    }
                                    
    $code_count++;
                                }
                                echo 
    "</li>";
                            }
                        }
                    }
                }
                echo 
    "</ul>";
            }
    ?>
    which is alot shorter than before
    cheers
      Reply With Quote

  6. #6
    Member janvt's Avatar
    Join Date
    Jan 2011
    Posts
    182

    Default 4 May 2011 @ 14.58

    for performance reasons I wouldn't select all the stores everytime you call the function. You have a couple options:
    1. move the code out of the function.
    2. cache the results and only fetch them during the first execution.
    3. modify your SQL statement to only select the stores you need (means you have 4 smaller statements, I would run with one of the other solution):
    Code:
    "SELECT  UPPER(SUBSTRING(stores.storeName,1,1)) AS letter, storeID, storeName,  rating FROM stores WHERE letter BETWEEN('$from','$to') ORDER BY storename ASC"
    Last edited by janvt; 4 May 2011 at @ 15.01.
      Reply With Quote

  7. #7
    Senior Member ljackson's Avatar
    Join Date
    Feb 2009
    Posts
    570

    Default 4 May 2011 @ 15.43

    i have tried the 3rd method but the code is throwing up an error
    Code:
    You have an error in your SQL syntax; check the manual that corresponds  to your MySQL server version for the right syntax to use near 'ORDER BY  storename ASC' at line 1
    any ideas?
    cheers mate
      Reply With Quote

  8. #8
    ian
    ian is offline
    Member ian's Avatar
    Join Date
    Jul 2010
    Posts
    201
    Blog Entries
    1

    Default 4 May 2011 @ 16.27

    It's
    Code:
    storeName
    in one place and
    Code:
    storename
    in the other. Correct one of them.
      Reply With Quote

  9. #9
    Member janvt's Avatar
    Join Date
    Jan 2011
    Posts
    182

    Default 4 May 2011 @ 16.30

    quote
    It's storeName in one place and storename in the other. Correct one of them.
    Originally Posted by ian View Post
    Field names aren't case sensitive (default value) in MySQL, that probably isn't the error. Could you post the whole query?
      Reply With Quote

  10. #10
    ian
    ian is offline
    Member ian's Avatar
    Join Date
    Jul 2010
    Posts
    201
    Blog Entries
    1

    Default 4 May 2011 @ 16.37

    Oh yeah, so they're not. I forgot.

    Ignore me.
      Reply With Quote

Page 1 of 3 123 LastLast

Similar Threads

  1. Collecting form data for display elsewhere?
    By scottgm in forum Javascript Libraries
    Replies: 2
    Last Post: 29 Nov 2010, @ 22.37
  2. How To Display Images on Website with Dreamweaver?
    By fbmagik in forum Just Starting Out - Help Me!
    Replies: 1
    Last Post: 17 Mar 2010, @ 02.59
  3. How Best To Display PDF files on my site
    By Ol'Canuck in forum Just Starting Out - Help Me!
    Replies: 13
    Last Post: 25 Feb 2010, @ 19.34

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •