Saturday 21 January 2012

Display records in php after connection

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Multiple Rows using PHP and MySQL</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />


</head>
<body>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script>
$(document).ready(function() {
$("tr:nth-child(even)").addClass("even");

 });


</script>

<div id="container">
    <div id="listing">
    <center><h1>IT and Computer Science Forum</h1></center>
    <!-- now we need to loop throguh and display our fields -->
    <?php
$username = "root";
$password = "";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
//echo "Connected to MySQL now you can create Table new one  <br>";
//select database
mysql_select_db("student_db",$dbhandle);
//echo "data Base Selected";

$query = "SELECT * FROM student";


// run the query and store the results in the $result variable.

$result =mysql_query($query,$dbhandle) or die("cannot do the query");


if ($result) {
  // create a new form and then put the results
  // indto a table.
  echo "<form method='post' action='delete.php'>";
  echo "<table cellspacing='0' cellpadding='15'>
         
          <th width='10%'>StudentID</th>
          <th width='10%'>StudentName</th>
        <th width='10%'>StudentImage</th>
        <th width='35%'>StudentQuestion</th>
        <th width='35%'>AnswerQuestion</th>
        ";
   
   
  while ($row = mysql_fetch_array($result)) {
        $student_id = $row['student_id'];
        $student_name = $row['student_name'];
        $student_image = $row['student_image'];
        $student_question = $row['student_question'];
        $answer_question = $row['answer_question'];
       
               
        //put each record into a new table row with a checkbox
    echo "<tr>
            <td>$student_id</td>
            <td>$student_name</td>
            <td><img src='$student_image' /></td>
            <td>$student_question</td>
            <td>$answer_question</td>
            <td><input type='checkbox' name='checkbox[]' id='checkbox[]'  value=$student_id />
                         </tr>";
   
    }
   
    // when the loop is complete, close off the list.
    echo "</table><p><input id='reply' type='submit' class='button' name='reply' value='Reply To Question'/></p></form>";
}


?>
    </div>
</div><!-- end container -->

</body>
</html>

No comments:

Post a Comment