SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: 2 Columns

  1. #1
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok.. i spent the last 2 hrs trying to figure this stooopid thing out... how can i print some information in 2columns? the info is coming from a mysql dbase... any one any ideas? im clueless
    Last edited by kunal; Apr 22, 2001 at 12:46.
    i dunno...

  2. #2
    SitePoint Guru DenverDave's Avatar
    Join Date
    Feb 2001
    Location
    Denver, Colorado
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is the problem?

    Usually the problem is getting anything at all to return from your query. If you are getting both fields, just place each field in a separate cell of an html table. or am I missing your Q?

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean two table columns? We'd need to see your code so far to give a proper answer but here's an example of a loop that can do just that:
    PHP Code:
    $connection mysql_connect("host""user""password");
    $database mysql_select_db("database"$connection);
    $result mysql_query("SELECT name, email FROM users ORDER BY name");

    // Got the data - now print the HTML for the start of the table
    echo "<table width=80% border=0><td><b>Name</b></td><td><b>E-Mail Address</b></td><tr>\n";

    while (
    $row mysql_fetch_array($result))
    {
        
    $name $row["name"];
        
    $email $row["email"];

        
    // Print a line of the HTML table with that information
        
    echo "<td>$name</td><td>$email</td><tr>\n";
    }

    // Now print the closing tag for the table
    echo "</table>\n"
    That (untested) code demonstrates how you can use a while loop to loop through the resutls from a database query and display each result in a new line in an HTML table - giving the effect of two columns of data.

  4. #4
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eeeks.. you guys got it all wrong

    the query returns a variable $m...
    i wanna display is like this

    $m $m
    $m $m


    in a table? get it? i cant figure the display loop out...
    i dunno...

  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)
    Skunk and DenverDave I think what he means is showing results accross two columns:

    PHP Code:
    <?
    $db 
    mysql_connect("localhost""root""");
    mysql_select_db("dbname");
    $result mysql_query("select * from tablename");

    $i 1;

    print 
    '<table border=1><tr>';

    while(
    $row mysql_fetch_array($result)) {
    printf('<td>%s</td>%s'$row["fieldname"], (is_int($i/2)) ? "</tr><tr>" "");
    $i++;
    }

    print (!
    is_int(mysql_num_rows($result) / 2)) ? '<td>&nbsp;</td></tr></table>' '</tr></table>';


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

  6. #6
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup.... thanx fred.. that fixed it
    i dunno...


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
  •