Thread: Tables

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    McMinnville, Tennessee, USA
    Posts
    1
    Rep Power
    0
    I was able to get MySQL to output to an HTML Table with the following code. I was even able to add color to the columns. The following code causes the color to run vertical. Anyone have suggestions on making the color run horizontal? Sorry for the length, but you some might find this useful.

    /* Output member list to an HTML table */
    if ($row = mysql_fetch_array($result)) {
    echo "<table border=0 cellpadding=5>n";
    echo "<tr>
    <td><b>User ID</b></td>
    <td><b>First Name</b></td>
    <td><b>Last Name</b></td>
    <td><b>Address1</b></td>
    <td><b>Address2</b></td>
    <td><b>City</b></td>
    <td><b>State</b></td>
    <td><b>Zip Code</b></td>
    <td><b>Country</b></td>
    <td><b>Phone</b></td>
    <td><b>Company</b></td>
    <td><b>Email Address</b></td>
    <td><b>Home Page</b></td>
    <td><b>URL</b></td>
    <td><b>Favorite URL</b></td>
    <td><b>User Name</b></td>
    <td><b>Password</b></td>
    <td><b>Password2</b></td>
    <td><b>Send Updates</b></td>
    <td><b>Gender</b></td>
    <td><b>Referral</b></td>
    </tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    do {
    printf("<tr>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</td>
    <td bgcolor='$tablecolor2'>%s</td>
    <td bgcolor='$tablecolor1'>%s</tr>n",
    $row["UserID"],
    $row["First_Name"],
    $row["Last_Name"],
    $row["Address1"],
    $row["Address2"],
    $row["City"],
    $row["State"],
    $row["Zip"],
    $row["Country"],
    $row["Phone"],
    $row["Company"],
    $row["Email"],
    $row["Home_Page"],
    $row["URL"],
    $row["Favorite_URL"],
    $row["User_Name"],
    $row["Password"],
    $row["Password2"],
    $row["Receive_Email"],
    $row["Gender"],
    $row["Referral"]);
    } while ($row = mysql_fetch_array($result));
    echo "n";
    } else {
    echo "Sorry, no records were found!";
    }

    [This message has been edited by Sysop (edited July 26, 2000).]
  2. #2
  3. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2000
    Location
    Enschede, The Netherlands
    Posts
    1,527
    Rep Power
    16
    err... I normally use 'print' instead of 'echo', so I don't know what's wrong with that statement, but I would do it as follows:

    do {
    print( "<tr><td>".$row["1"]."</td></tr>" );
    }
    while( ... )

    The rest seems ok to me!
    Hope this helps!

    Mirax
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Hi,

    actually you have missed a "<td>"close in your printf()..
    I think that might have caused the problem..


    <<
    <td bgcolor='$tablecolor1'>%s</tr>n",
    >>


    <td bgcolor='$tablecolor1'>%s</td></tr>n",

    other things are ok!!!


    Good Luck!!!




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. Large tables or many small tables?
    By Tassadar356 in forum MySQL Help
    Replies: 4
    Last Post: February 8th, 2004, 01:07 PM
  2. tables get corrupted
    By 90coders in forum MySQL Help
    Replies: 1
    Last Post: December 5th, 2003, 05:23 AM
  3. Replies: 0
    Last Post: October 15th, 2003, 08:02 PM
  4. Synchronizing 2 tables with different field structure
    By nickcwj in forum Database Management
    Replies: 0
    Last Post: October 15th, 2003, 07:55 PM
  5. variables and mysql tables ids help!
    By iamkeith26 in forum PHP Development
    Replies: 1
    Last Post: July 27th, 2003, 08:58 PM

IMN logo majestic logo threadwatch logo seochat tools logo