Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    104
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Dynamic table with bullets question

    Hello Guys,

    I have a script that creates a dynamic <tr> from the a db query. The issue I am having is that it creates more bullets than are needed. Here is my script

    PHP Code:
    // First Query to grab Feature1
    $result mysql_query("SELECT * FROM features WHERE f_id IN ( $feature3 )
    "
    ) or die("Sql error : " mysql_error());

    while(
    $row mysql_fetch_assoc ($result)){
    //        $f_name=$row["f_name"];
    //        echo "<br>".$f_name;
         // -- This array will hold your data, 
        // -- I used it to hold a title, an id and an author 
        // -- but it can be extended based on your own needs
            
    $items[] = array(=> $row['f_name']);
        }
            
    // Default # of Columns
            
    $numcols 3;

            
    // Number of Items
            
    $numitems count($items);

            
    // Number of Rows
            
    $numrows ceil($numitems/$numcols);

            echo 
    '<table border="0" bgcolor="#f0eeee" width="97%">';
            for (
    $row=1$row <= $numrows$row++)
            {
                
    $cell 0;
                echo 
    ' <tr>'."\n";
                for (
    $col=1$col <= $numcols$col++)
                {
                echo 
    '  <td width="'.round(100/$numcols).'%">'."\n";

                if (
    $col===1)
                {
                    
    $cell += $row;
                    print 
    "<div class=\"feaureitems\"><img src=\"images/squarebul.png\">&nbsp;".$items[$cell 1][1]."</div>"/*  $items[$cell - 1][1] to display title  $items[$cell - 1][2] etc... */
                
    }
                else {
                    
    $cell += $numrows;
                    print 
    "<div class=\"feaureitems\"><img src=\"images/squarebul.png\">&nbsp;".$items[$cell 1][1]."</div>";
                }
                echo 
    '  </td>'."\n";
                }
                echo 
    ' </tr>'."\n";
            }
            echo 
    '</table>';


        }

    Here is the problem (See attachment)

    What can I do to stop this from happening?
    Attached Thumbnails Attached Thumbnails Dynamic table with bullets question-2012-01-30_0756.png  

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    What is the purpose of the array called $items ?

    You have a MySQL database ... that contains all the information you need.
    When you query it, the result is already an array. I'm confused.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    104
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Hey thanks for the response.. I think it's because in the database the table holds values like 1,2,3,4,5

    I am converting them to an array.. That part actually works well.. Its the additional <td>'s being created with the bullets is the problem.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    PHP Code:

                
    if ($col===1)
                {
                    
    $cell += $row;
    if(
    $items[$cell 1][1]){
                    print 
    "<div class=\"feaureitems\"><img src=\"images/squarebul.png\">&nbsp;".$items[$cell 1][1]."</div>"/*  $items[$cell - 1][1] to display title  $items[$cell - 1][2] etc... */
    }
                }
                else {
                    
    $cell += $numrows;
    if(
    $items[$cell 1][1]){
                    print 
    "<div class=\"feaureitems\"><img src=\"images/squarebul.png\">&nbsp;".$items[$cell 1][1]."</div>";
                }

    I still think there's something wrong with the way the arrays are being used,
    but maybe I just don't know what your site is about. I just have a hunch
    that you're making it much harder than it needs to be.


    .

  • Users who have thanked mlseim for this post:

    dk4210 (01-30-2012)

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Are you intending to display it effectively by column and then row, putting the padded results into the last column instead of the last row?
    You don't need to actually capture the additional array if you don't need to use it outside of this fetch. If you do, then yeah an array would probably make the most sense.

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    104
    Thanks
    13
    Thanked 0 Times in 0 Posts
    That worked thanks!


  •  

    Posting Permissions

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