Web Analytics Made Easy -
StatCounter Displaying Data in the Correct Area - CodingForum

Announcement

Collapse
No announcement yet.

Displaying Data in the Correct Area

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Displaying Data in the Correct Area

    I am inserting data to mysql and then at the same time retrieving it.
    While retrieving i cannot put it to the place where i want.
    I want to dispaly the data below the header.
    I have a registration form(which is in php) below the header (which is in html) when user submits the registration form at the same time and the same area i want to retrieve all records from the table.I have this code:
    PHP Code:
    if (isset($_POST['submit_registration_x'])){
    include 
    "connection.php";
    $table_name "registration";
    $sql "INSERT INTO $table_name (id, name, father_name, gender, address)
            VALUES ('
    $_POST[id]', '$_POST[name]', '$_POST[father_name]', '$_POST[gender]', '$_POST[address]')";
    $result = @mysql_query($sql$connection) or die (mysql_error());
    $sql "SELECT * from $table_name";
    $result mysql_query($sql$connection) or die (mysql_error());
    echo 
    "<form method='post' action='student.php' name='student_records'>
          <table border='1' cellspacing='4' cellpadding='2' align='center'>
          <tr><th>ID</th><th>Name</th><th>Father's Name</th><th>Gender</th><th>Address</th></tr>"
    ;
    while(
    $row mysql_fetch_array($result)){
        
    $id $row['id'];
        
    $name $row['name'];
        
    $father_name $row['father_name'];
        
    $gender $row['gender'];
        
    $address $row['address'];
        echo
    "<tr><td>$id</td><td>$name</td><td>$father_name</td><td>$gender</td><td>$address</td></tr>";
        }
        echo 
    "</table></form>";
    }
    ?> 

  • #2
    As you know, you can imbed PHP code anywhere in your document. So instead of displaying the data inside your fetch loop, have your fetch loop do nothing but build an array, then do the displaying part at the appropriate spot in the markup using a foreach loop on the array you built earlier.

    Comment

    Working...
    X