SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    categories layout

    Hi all,

    I've decided to start reworking a script I written a few months ago and have been trying to alter the output which displays the category links.

    Currently when i output any dynamic content it apears like so :

    - category link 1
    - category link 2
    - category link 3
    and so on...

    However Ive noticed many scripts displaying there out put in a different manor.

    - category link 1 | - category link 2 | - category link 3
    - categpry link 4 | - categpry link 3 | and so on...

    Is there a tutorial that anyone knows of or could someone point me in the right direction to help me work through this problem I'm having.

    Best Regards
    Dean Greasley

  2. #2
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I proposed a solution to a similar problem in this thread: http://www.sitepoint.com/forums/showthread.php?t=149966. The solution could be modified to output 3 columns for your category display.

    JT

  3. #3
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Seratonin,

    Thanks for your speedy reply much apreciated, however your proposed work around looks a little confusing for me 'excuse my lack of knowledge' as the out put im currently using is simular to this :

    PHP Code:
    echo ('<table cellpadding="0" cellspacing="0" border="0">');
    echo (
    '<tr>');
    while ( 
    $row mysql_fetch_array($result) ) {
        
    $id $row['id'];
        
    $title $row['title'];
        
    $thumb $row['thumb'];

        echo 
    '<td><a href='.$somelink.'><img src="$someimage'" alt='.$title.' border="0" /></a></td>';
    } // wend

    echo ('</tr>');
    echo ('</table>'); 
    and i would know how to implement your work around.

    Best Regards

    Dean Greasley

  4. #4
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at Frezno's script, post #5

    Slightly more complex, though more flexible ?

    http://www.sitepoint.com/forums/showthread.php?t=128624

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    // Create an array to store all of the rows in the database result
    $rows = array();

    // Transfer rows from database result into an array
    while ($row mysql_fetch_array($result)) {
        
    $rows[] = $row;
    }

    // Each row in the database result corresponds one element in the table
    $total count($rows);    // total table cells

    if ($total != 0) {
        
    // if the total number of elements is not evenly divisble by 3, calculate the next largest number that is
        
    $total += (- ($total 3));
    }

    $j 0;

    echo 
    '<table cellpadding="0" cellspacing="0" border="0">';     // begin table

    while ($j $total) {
        echo 
    "<tr>";    // begin table row

        // for each column in the table
        
    for ($i 0$i 3$i++) {
            if (isset(
    $rows[$j]) {
                
    // if there is an element to display
                
    $id $rows[$j]['id'];
                
    $title $rows[$j]['title'];
                
    $thumb $rows[$j]['thumb'];
                echo 
    '<td><a href="' $somelink '"><img src="' $someimage '" alt="' $title .'" border="0" /></a></td>'
            } else {
                
    // we ran out of elements but must finish the table
                
    echo "<td>&nbsp;</td>";
            }
            
    $j++;
        }
        
        echo 
    "</tr>";    // end table row
    }

    echo 
    "</table>";    // end table
    ?>
    Here is how I would use my previous solution to solve your specific problem. The solution could be made more robust if constants were used to specify the total number of columns desired.

    JT
    Last edited by seratonin; Mar 4, 2004 at 11:11.

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    define
    ('NUM_COLUMNS'5);

    $filenames = array("file1.jpg""file2.jpg""file3.jpg""file4.jpg""file5.jpg""file6.jpg""file7.jpg");

    $total count($filenames);

    if (
    $total NUM_COLUMNS != 0) {
        
    $total += (NUM_COLUMNS - ($total NUM_COLUMNS));
    }

    $j 0;

    echo 
    '<table border="1">';

    while (
    $j $total) {
        echo 
    "<tr>";
        
        for (
    $i 0$i NUM_COLUMNS$i++) {
            if (isset(
    $filenames[$j])) {
                echo 
    '<td><img src="' $filenames[$j] . '"/></td>';
            } else {
                echo 
    "<td>&nbsp;</td>";
            }
            
    $j++;
        }
        
        echo 
    "</tr>";
    }

    echo 
    "</table>";
    ?>
    My previous solution with a constant for the desired number of columns.

    JT

  7. #7
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx Seratonin,

    By looking at your second post, this method is a little more understandable for me, I thankyou again for making it more plain for me. I will be trying this out tonight, I will be posting here a little more in this topic concerning a few other issues that im working on.

    Thx again for your support, users like you make this forum one of the best on the world wide wait.

    Best Regards
    Dean Greasley

  8. #8
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ive tried to implement the work around you written (quote below)but for some unknown reason to me, it displays a error on line 73 I've had many hours of scratching my head and i think im starting to lose a little hair he and there. I just cant seem to see where the problem resides, here's the code to which im trying to implement, here's the code below hope someone can see where the problem is

    Quote Originally Posted by seratonin
    PHP Code:
    <?php
    // Create an array to store all of the rows in the database result
    $rows = array();

    // Transfer rows from database result into an array
    while ($row mysql_fetch_array($result)) {
        
    $rows[] = $row;
    }

    // Each row in the database result corresponds one element in the table
    $total count($rows);    // total table cells

    if ($total != 0) {
        
    // if the total number of elements is not evenly divisble by 3, calculate the next largest number that is
        
    $total += (- ($total 3));
    }

    $j 0;

    echo 
    '<table cellpadding="0" cellspacing="0" border="0">';     // begin table

    while ($j $total) {
        echo 
    "<tr>";    // begin table row

        // for each column in the table
        
    for ($i 0$i 3$i++) {
            if (isset(
    $rows[$j]) {
                
    // if there is an element to display
                
    $id $rows[$j]['id'];
                
    $title $rows[$j]['title'];
                
    $thumb $rows[$j]['thumb'];
                echo 
    '<td><a href="' $somelink '"><img src="' $someimage '" alt="' $title .'" border="0" /></a></td>'
            } else {
                
    // we ran out of elements but must finish the table
                
    echo "<td>&nbsp;</td>";
            }
            
    $j++;
        }
        
        echo 
    "</tr>";    // end table row
    }

    echo 
    "</table>";    // end table
    ?>
    Here's the code im trying to set around the above :

    PHP Code:
    <?php 

    include("conf.php" ); 

    $connection mysql_connect($host$user$pass) or die ("Unable to connect!" ); 

    mysql_select_db($db) or die ("Unable to select database!" ); 

    $com_links_categories = @mysql_query('SELECT ID,name FROM com_links_categories'); 
    if (!
    $com_links_categories) { 
    die(
    'Error retrieving categories from the database!'
    'Error: ' mysql_error() . '</p>'); 


    $query ' SELECT cat.ID, cat.name, count(*) as total FROM com_links_categories cat, com_links WHERE cat.ID = cid GROUP BY cat.ID,cat.name ORDER BY id DESC'

    $com_links_categories = @mysql_query($query); 

    while (
    $cat mysql_fetch_array($com_links_categories)) 

      echo(
    '<br class="txtnormal"><img src="images/heading_icon.png" align="absmiddle" align="absmiddle"> <a href="php/community_links/display_inc.php?id=' $cat['ID'] . '">' $cat['name'] . '</a> (' $cat ['total'] . ')<br>'); 


    ?>
    fingers crossed, i hope somehow this can be worked within.

    Cheers Deano
    Last edited by Deano; Mar 7, 2004 at 10:21.


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
  •