SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Two Columns

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two Columns

    Hi all,

    I have a basic select query that selects categories from a MySQL table.

    What I need is something where it will show the first half of the records in teh left column, and the second half in the right column.

    I know that I could use limits, but then if I add a lot of categories, I have to change the code. I want it to all be controlled dynamically.

    Any help is greatly appreciated.

    -Corbb
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you not use mysql_num_roms to count the total number of records then have then use LIMIT to pull out half of the categories, based on the result of the NUM_ROWS query?

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi HarryF,

    I never thought of that.

    Thanks a lot.

    -Corbb
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should be fun

    PHP Code:
    $sql "SELECT * FROM $table";
    $num_rows mysql_num_rows(mysql_query($sql));
    if((
    $num_rows 2) != 0){
        
    $left_col = (($num_rows 2) + .5 );
        
    $right_col $num_rows $left_col;
    }else{
        
    $left_col $num_row 2;
        
    $right_col $left_col;
    }

    $left_sql "SELECT * FROM $table LIMIT 0, $left_col";
    $right_sql "SELECT * FROM $table LIMIT $left_col$right_col"
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should only need anduse one query, no need to query the db three times for this.

    PHP Code:
    <table width="600" border="1"><tr valign="top"><td><table>
    <?

    $db 
    mysql_connect("host""user""pass");
    mysql_select_db(db);
    $result mysql_query("select* from tablename");
    $limit ceil(mysql_num_rows($result)/2);

    $i 0;
    while(
    $row mysql_fetch_array($result)) {
        
    extract($row);
        print 
    "<tr><td>$field1</td></tr>";

        if(
    $i == $limit) {
            print 
    '</table></td><td><table>';
            }
        
    $i++;
        }


    ?>
    </td></tr>
    </table>
    </td></tr>
    </table>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    corrected once again...
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


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
  •