SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: i need help

  1. #1
    SitePoint Enthusiast grubindex.com's Avatar
    Join Date
    Apr 2001
    Location
    DC
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you pull data from mysql into tables like this:

    data1 | data2
    data3 | data4

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to pull data from a table like that or pull data from mysql and print it to a table like that?


    to pull from simply do this:

    Code:
    //assuming field = "data1 | data2"
    
    $field_array = explode("|",$field); 
    
    print("$field_array[0]");
    // prints data1
    
    print("$field_array[1]");
    // prints data2
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  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'm sorry for the confusion but i meant into seperate 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)
    You could loop through the results and test to see whether your counter is divisble by 2, if it is you know you need a new row, so try something like this:

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

    else {
    print 
    "</tr>";
    }
    ?>
    </table>
    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)
    yo know how on yahoo there are two columns of links for all the sections. i want the same thing

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had one small parse error in there, and no where to check it last night sorry, but this is what you described in your first post, and it works I just tried it.

    PHP Code:

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

    else {
    print 
    "</tr>";
    }
    ?>
    </table>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •