Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts

    New line after echoing .$row['column'];

    How would I echo a new line after echoing row data

    PHP Code:
    <?php


    mysql_connect
    ("localhost""root""root") or die(mysql_error());
    mysql_select_db("auth") or die(mysql_error());


    $result mysql_query("SELECT * FROM users")
    or die(
    mysql_error());  

    $row mysql_fetch_array$result );

    echo 
    " ID: ".$row['id'];    //would like a new line here
    echo " Username: ".$row['username'];   //would like a new line here
    echo " Password: ".$row['password'];        //would like a new line here
    echo " Email: ".$row['email'];             //would like a new line here
    echo " Active Status: ".$row['isactive'];     //would like a new line here
    echo " Active Key: ".$row['activekey'];    //would like a new line here
    echo " Reset Key: ".$row['resetkey'];      //would like a new line here


    ?>
    Last edited by amcf1992; 02-01-2013 at 09:06 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    This put it into a table.

    PHP Code:
    <?php
    $db_host 
    'localhost';
    $db_user 'user';
    $db_pwd 'pass';

    $database 'database';
    $table 'table';

    if (!
    mysql_connect($db_host$db_user$db_pwd))
        die(
    "Can't connect to database");

    if (!
    mysql_select_db($database))
        die(
    "Can't select database");

    // sending query
    $result mysql_query("SELECT * FROM {$table}");
    if (!
    $result) {
        die(
    "Query to show fields from table failed");
    }

    $fields_num mysql_num_fields($result);

    echo 
    "<p>";
    echo 
    "<table border='1' class='dataTable'><tr>";
    // printing table headers
    for($i=0$i<$fields_num$i++)
    {
        
    $field mysql_fetch_field($result);
        echo 
    "<th>{$field->name}</th>";
    }
    echo 
    "</tr>\n";
    // printing table rows
    while($row mysql_fetch_row($result))
    {
        echo 
    "<tr>";

        
    // $row is array... foreach( .. ) puts every element
        // of $row to $cell variable
        
    foreach($row as $cell)
            echo 
    "<td>$cell</td>";

        echo 
    "</tr>\n";
    }
    mysql_free_result($result);
    ?>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •