1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help constraining a table width.

Discussion in 'HTML & Website Design' started by articledirectory, May 8, 2008.

  1. #1
    I have a joke site where i have more than 5,000 jokes in a miscellaneous jokes category and it tries to display a paging result: page 1, 2, 3, etc
    all the way up to 138 which puts the template out of shape.

    the code using for the paging is this

    <? if($page > 1){ 
        $prev = ($page - 1); 
        echo "<a href='".get_cat_url($id,$prev,$make)."'><<Previous</a>&nbsp;"; 
    } for($i = 1; $i <= $total_pages; $i++){ 
        if(($page) == $i){ 
            echo "$i&nbsp;"; 
            } else { 
                echo "<a href='".get_cat_url($id,$i,$make)."'>$i</a>&nbsp;"; 
        } 
    } 
    
    // Build Next Link 
    if($page < $total_pages){ 
        $next = ($page + 1); 
        echo "<a href='".get_cat_url($id,$next,$make)."'>Next>></a>"; 
    } ?>
    Code (markup):
    i tried putting the code inside a table with a fixed width of 275px hoping that the results would go up to a width of 275, then continue on the next line down, but all it wants to do is one continuous long line of results.

    <table width="275" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><? if($page > 1){ 
        $prev = ($page - 1); 
        echo "<a href='".get_cat_url($id,$prev,$make)."'><<Previous</a>&nbsp;"; 
    } for($i = 1; $i <= $total_pages; $i++){ 
        if(($page) == $i){ 
            echo "$i&nbsp;"; 
            } else { 
                echo "<a href='".get_cat_url($id,$i,$make)."'>$i</a>&nbsp;"; 
        } 
    } 
    
    // Build Next Link 
    if($page < $total_pages){ 
        $next = ($page + 1); 
        echo "<a href='".get_cat_url($id,$next,$make)."'>Next>></a>"; 
    } ?></td>
      </tr>
    </table>
    Code (markup):
    Can someone suggest a fix either with the table code or the paging result code.

    Thanks in advance. :)
     
    articledirectory, May 8, 2008 IP
  2. BlogSalesman

    BlogSalesman Well-Known Member

    Messages:
    1,687
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Or try writing 20 out, and put a <br /> in.

    I hate tables, so it may not work.
     
    BlogSalesman, May 8, 2008 IP
  3. articledirectory

    articledirectory Peon

    Messages:
    1,704
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Tried using
    <td style="width: 275px;"> 
    Code (markup):
    but it didn't help it still displaying in one continuous line :(
    Any one else have any other ideas?
     
    articledirectory, May 9, 2008 IP
  4. BlogSalesman

    BlogSalesman Well-Known Member

    Messages:
    1,687
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #4
    Try doing something with this:

    I see a lot of width:100%. Try changing them to fixed numbers and see if it fixes it.

    Also, you may want to try rewriting it using divs and CSS.
     
    BlogSalesman, May 9, 2008 IP
  5. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try this:

    
    <?
    
    if($page > 1){ 
      $prev = ($page - 1); 
      echo "<a href='".get_cat_url($id,$prev,$make)."'><<Previous</a>&nbsp;"; 
    }
    
    // INCREASE OR DECREASE THIS VALUE AS YOU SEE FIT 
    $max_per_row = 10;
    
    $cnt = 0;
    for($i = 1; $i <= $total_pages; $i++){ 
      if(($page) == $i){ 
        echo "$i&nbsp;"; 
      }
      else { 
        echo "<a href='".get_cat_url($id,$i,$make)."'>$i</a>&nbsp;"; 
      }
    
      $cnt = $cnt + 1;
      if(($cnt % $max_per_row) == 0){
        echo "<br>";
      }
    } 
    
    // Build Next Link 
    if($page < $total_pages){ 
        $next = ($page + 1); 
        echo "<a href='".get_cat_url($id,$next,$make)."'>Next>></a>"; 
    }
    
    ?>
    
    Code (markup):
    change $max_per_row to suit yourself...
     
    daboss, May 9, 2008 IP
    articledirectory likes this.
  6. articledirectory

    articledirectory Peon

    Messages:
    1,704
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks

    The code worked a treat, i have +Rep'd you.

    you are "daboss" :)

     
    articledirectory, May 9, 2008 IP
  7. BlogSalesman

    BlogSalesman Well-Known Member

    Messages:
    1,687
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #7
    I guess when I said it before, I was talking out my a$$ ...
     
    BlogSalesman, May 9, 2008 IP
    articledirectory likes this.
  8. articledirectory

    articledirectory Peon

    Messages:
    1,704
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #8
    LOL!

    I don't think you are talking out your a$$, i just didn't understand what you were trying to say, i understand html, but php and dynamic statements are way over my head..

    Thanks for your help also +Rep to you as well.
     
    articledirectory, May 9, 2008 IP