Results 1 to 6 of 6

Thread: table help

  1. #1
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default table help

    i have the following script and need help with some of the table work

    id like to have the cells when new ones are added they go horizontal until they reach 4 colomns then drop down a row. how would i accomplish taht?

    PHP Code:
    <?php
    include 'config.php';
    include 
    'opendb.php';

    $query  "SELECT name, date, Email, message FROM contact";
    $result mysql_query($query);
    echo 
    '<table border="5" BORDERCOLORLIGHT=YELLOW BORDERCOLORDARK=BLUE bgcolor="#6699ff" width="200px"><tr><td>';
    while(
    $row mysql_fetch_assoc($result))
    {
    echo 
    '<tr>';
    echo 
    '<td>';
        echo 
    "Date : {$row['date']} <br>" .
             
    "Name :{$row['name']} <br>" .
             
    "Email : {$row['Email']} <br>" .
             
    "Message : {$row['message']} <br><br>";
    echo 
    '</tr>';
    echo 
    '</td>';
    }

    echo 
    '</table>';
    include 
    'closedb.php';
    ?>
    <html>
    <body bgcolor="black">


    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Here is a PHP calendar which does the same thing after 7 rows, see what you can grab from it...

    Code:
    <?php 
    //This gets today's date 
    $date =time () ; 
    
    //This puts the day, month, and year in seperate variables 
    $day = date('d', $date) ; 
    $month = date('m', $date) ; 
    $year = date('Y', $date) ;
    
    //Here we generate the first day of the month 
    $first_day = mktime(0,0,0,$month, 1, $year) ; 
    
    //This gets us the month name 
    $title = date('F', $first_day) ; 
    
    //Here we find out what day of the week the first day of the month falls on 
    $day_of_week = date('D', $first_day) ; 
    
    //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
    switch($day_of_week){ 
    case "Sun": $blank = 0; break; 
    case "Mon": $blank = 1; break; 
    case "Tue": $blank = 2; break; 
    case "Wed": $blank = 3; break; 
    case "Thu": $blank = 4; break; 
    case "Fri": $blank = 5; break; 
    case "Sat": $blank = 6; break; 
    }
    
    //We then determine how many days are in the current month
    $days_in_month = cal_days_in_month(0, $month, $year) ; 
    
    //Here we start building the table heads 
    echo "<table border=1 width=294>";
    echo "<tr><th colspan=7> $title $year </th></tr>";
    echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>";
    
    //This counts the days in the week, up to 7
    $day_count = 1;
    
    echo "<tr>";
    //first we take care of those blank days
    while ( $blank > 0 ) 
    { 
    echo "<td></td>"; 
    $blank = $blank-1; 
    $day_count++;
    } 
    
    //sets the first day of the month to 1 
    $day_num = 1;
    
    //count up the days, untill we've done all of them in the month
    while ( $day_num <= $days_in_month ) 
    { 
    echo "<td> $day_num </td>"; 
    $day_num++; 
    $day_count++;
    
    //Make sure we start a new row every week
    if ($day_count > 7)
    {
    echo "</tr><tr>";
    $day_count = 1;
    }
    } 
    
    //Finaly we finish out the table with some blank details if needed
    while ( $day_count >1 && $day_count <=7 ) 
    { 
    echo "<td> </td>"; 
    $day_count++; 
    } 
    
    echo "</tr></table>"; 
    
    ?

  3. #3
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i dont see how there doing it but thank you for tyhe post

  4. #4
    Join Date
    Jan 2008
    Location
    Portland, Oregon
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    echo '<tr>';
    echo '<td>';
    echo "Date : {$row['date']} <br>" .
    "Name :{$row['name']} <br>" .
    "Email : {$row['Email']} <br>" .
    "Message : {$row['message']} <br><br>";
    echo '</tr>';
    echo '</td>';


    Lets take a look at this block from your current code...
    and you want it to ouput: DATE:
    NAME:
    EMAIL:
    MESSAGE: (format)
    <line break>

    rewrite the block to look like this:

    echo <tr><td> Date: {$row['date']} </td></tr>
    echo <tr><td> Name: {$row['name']} </td></tr>
    echo <tr><td> Email: {$row['email']} </td></tr>
    echo <tr><td> Message: {$row['message']} </td></tr>
    echo <br/>

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Heh, I'd use quotes in my echo lines, but that's just me I figure the missing <?php ?> tags were implied.

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by howellsgs View Post
    echo '<tr>';
    echo <tr><td> Date: {$row['date']} </td></tr>
    echo <tr><td> Name: {$row['name']} </td></tr>
    echo <tr><td> Email: {$row['email']} </td></tr>
    echo <tr><td> Message: {$row['message']} </td></tr>
    echo <br/>
    First, james is correct in that your echo's should be quoted.
    If you wish to use the same structure as you have there you would need double quotes, because single quotes do not allow for variable parsing. you also need to have semi-colon's at the end of each line because whitespace doesn't mean anything to a computer.
    Code:
      echo "<tr><td> Date: {$row['date']} </td></tr>";
      echo "<tr><td> Name: {$row['name']} </td></tr>";
      echo "<tr><td> Email: {$row['email']} </td></tr>";
      echo "<tr><td> Message: {$row['message']} </td></tr>";
    The other method would be to get rid of the curly braces, and use concantenation to assign the variable

    Code:
      echo "<tr><td> Date: ". $row['date'] ." </td></tr>";
      echo "<tr><td> Name:". $row['name'] ." </td></tr>";
      echo "<tr><td> Email: ". $row['email'] ." </td></tr>";
      echo "<tr><td> Message: ". $row['message'] ." </td></tr>";

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
  •