SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast grubindex.com's Avatar
    Join Date
    Apr 2001
    Location
    DC
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result=mysql_query("SELECT * FROM cat");
    $category mysql_fetch_array($result);

    $i 1;
    $numrows mysql_numrows($result);
    while(
    $row=mysql_fetch_array($result)) {
    $cat=($row["category"]);
    extract($row);
    printf('<td>%s</td>%s, $category, (($i%2) == 0) ? "</tr><tr>\n" : "");
    $i++;
    }
    if(($numrows%2 == 1)) {
    print "<td>&nbsp;</td></tr>";

    else {
    print "</tr>";
    }
    ?> 
    help

  2. #2
    SitePoint Zealot theFinn's Avatar
    Join Date
    Oct 2000
    Location
    Edmonton
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow..thats nasty try this:

    PHP Code:
    $i 1// Don't forget this
    while($row mysql_fetch_array($result))
    {
       
    extract($row);
       if(!(
    $i 2))
       {
          
    $extra "</tr><tr>";
       }
       echo 
    "<td>$category</td>$extra";
       
    $i++;
    }
    ... 
    Not only is it more readable but it'll work...
    - theFinn
    Creator and Project Manager, phpBB
    http://www.theFinn.net
    http://www.tarotclass.com

  3. #3
    SitePoint Enthusiast grubindex.com's Avatar
    Join Date
    Apr 2001
    Location
    DC
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need two columns

  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)
    It wasn't nasty in the beginning, it wasn't till after it was butchered that it became nasty. It shoul read like this:

    Code:
    print "<table><tr>";
    $result=mysql_query("SELECT * FROM cat");
    $numrows = mysql_numrows($result);
    $i = 1;
    while($row=mysql_fetch_array($result)) {
       extract($row);
       printf('<td>%s</td>%s, $category, ((($i%2) == 0) && ($i != $numrows)) ? "</tr><tr>\n" : "");
       $i++;
       }
    if(($numrows%2 == 1)) {
       print "<td>&nbsp;</td></tr>";
       } 
    else {
       print "</tr>";
       }
    print "</table>";
    Last edited by freddydoesphp; Apr 30, 2001 at 17:27.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast grubindex.com's Avatar
    Join Date
    Apr 2001
    Location
    DC
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that doesn't work.


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
  •