SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: dynamic tables

  1. #1
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am retrieving data from my DB and constructing it into a dynamic table. This I know how to do. What I'm having trouble figuring out is how to code the table so it will be only so many columns wide before it starts a new row. This is my logic so far:

    WHILE loop through my query
    COUNT the total number of records being retrieved
    DIVIDE the COUNT by the number of columns I want in the table
    FOR loop through the DIVIDED count
    PRINT out the data in a row while in the FOR loop
    GOTO the next FOR LOOP for the next table row

    How am I doing so far?? Could someone help piece this together? My main problem is I don't know how to go from one FOR loop (first row) to the next one. I figure I need to capture it into an array and loop certain portions of the array at different times, right????
    Joe Eliason
    Just a dog learnin' PHP from cat.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Joe, this is a common and easily fixable probelm see my code below. Please adjust it to make it work for your situation:


    PHP Code:
    <table border=1><tr>
    <?php
    $count 
    1;
    $numcols 3;
    for(
    $i=0;$i<33;$i++) {
        print 
    "<td>$i</td>";
        print (
    is_int($count/$numcols)) ? "</tr><tr>" "";
        
    $count++;
        }


    ?>
    </tr></table>
    Just put your while loop instead of the for() loop I have
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works great!!! Here is my actual code:

    Code:
    <?php
    	$sql = ("SELECT groupNmbr, name FROM gaclients");
    	$query = mysql_query($sql);
    	
    	echo "<table border=1><tr>";
    	$count = 1;
    	$numcols = 4;
    	while ($client = mysql_fetch_array($query)) {
    		$cid = $client["groupNmbr"];
    		$cname = $client["name"];
    	    print "<td>$cname</td>";
    	    print (is_int($count/$numcols)) ? "</tr><tr>" : "";
    	    $count++;
    	    }
    
    
    ?
    BTW... from my other post question. I was able to find a way to auto fill my form once a client name or group number was entered. Take a look at it if you'd like and tell me what you think. But I'm still wondering if it is possible to pass a javascript string value to a php variable.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where can I see it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Joe Eliason
    Just a dog learnin' PHP from cat.


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
  •