1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

newbi, how to make a table using php echo

Discussion in 'PHP' started by shadow_boi, Nov 18, 2007.

  1. #1
    Hi, I want to make a table (3 rows x 3 cols),
    I dont know how and to to take care of the <tr></tr>

    Right now i can only make a table with 1 row. totaly newbie here.

    
    
    echo '<table><tr><td>';
    
    if($EntriesCount%3 == 0)
           {
    	echo '</td><td>';		
            }
    
    echo '</td></tr></table>';
    
    
    PHP:

    Please help. Thanks
     
    shadow_boi, Nov 18, 2007 IP
  2. Claudek

    Claudek Well-Known Member

    Messages:
    1,379
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    165
    #2
    If you have your html code for your table and simply want to echo it to be used in a php file, I suggest you go to http://www.quasarcr.com/html2php/ and put in your html, choose the echo option and use the result. The \n is also useful when you have javascript you want to convert to php code.
     
    Claudek, Nov 18, 2007 IP
  3. shadow_boi

    shadow_boi Peon

    Messages:
    374
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks. and i have figured out how to do that.
     
    shadow_boi, Nov 18, 2007 IP
  4. mohitspage

    mohitspage Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hey..
    i dont know why but this code dint work when i run the same script....
    i have run this script to fetch all data from mysql table through php.....
    please suggest me what to do....
    thanks..
     
    mohitspage, Jun 1, 2012 IP
  5. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #5
    Here's a quick example:
    <?php
    
    $conn = mysql_connect("localhost", "mysql_user", "mysql_password");
    
    if (!$conn) {
        echo "Unable to connect to DB: " . mysql_error();
        exit;
    }
      
    if (!mysql_select_db("mydbname")) {
        echo "Unable to select mydbname: " . mysql_error();
        exit;
    }
    
    $sql = "SELECT id as userid, fullname, userstatus 
            FROM   sometable
            WHERE  userstatus = 1";
    
    $result = mysql_query($sql);
    
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    
    echo '<table><tbody>';	// <-- starting tags of table
    while ($row = mysql_fetch_assoc($result)) {
        echo '<tr>';	// <-- starting of row
        echo '<td>' . $row["userid"] 	. '</td>'; // column1
        echo '<td>' . $row["fullname"]	. '</td>'; // column2
        echo '<td>' . $row["userstatus"] . '</td>'; // column3
        echo '</tr>';	// <-- end of row
    }
    echo '</tbody></table>'; // <-- end tags of table
    
    mysql_free_result($result);
    
    ?>
    PHP:
     
    akhileshbc, Jun 1, 2012 IP