Page 1 of 1

Simple list php+Mysql

Posted: 28/09/2012 2:50 pm
by mindphp

Code: Select all

<?php
    $link = @mysql_connect('localhost', 'root', '') or die(  mysql_error() );    //1
    @mysql_select_db('test_mtu', $link) or die( mysql_error() );    // 2
    
    $sql = "SELECT * FROM `orders` LIMIT 0,15 ";                    // 3
    
    $re     =    mysql_query($sql, $link) or die(  mysql_error() );        //3
    
    $n_row = mysql_num_rows($re);                //4
    $a_row = array();
    while( $row = mysql_fetch_assoc( $re)  ){
            $a_row[]    = $row;
        }
    
    mysql_free_result($re);        // 6
    mysql_close($link);                // 6
?>    
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
ตาราง orders มีข้อมูลทั้งหมด 
<?php 
// 5
    echo $n_row; 
?> 
แถว
<table width="100%" border="1">
  <tr>
    <td>OrdNo</td>
    <td>OrdDate</td>
    <td>CustNo</td>
    <td>EmpNo</td>
    <td>OrdName</td>
    <td>OrdStreet</td>
    <td>OrdCity</td>
    <td>OrdState</td>
    <td>OrdZip</td>
  </tr>
  <?php 
  // 5
  foreach($a_row as $k=>$row){ ?>
  <tr style="background-color:#CCC">
    <td><?php echo $row['OrdNo']; ?></td>
    <td><?php echo $row['OrdDate']; ?></td>
    <td><?php echo $row['CustNo']; ?></td>
    <td><?php echo $row['EmpNo']; ?></td>
    <td><?php echo $row['OrdName']; ?></td>
    <td><?php echo $row['OrdStreet']; ?></td>
    <td><?php echo $row['OrdCity']; ?></td>
    <td><?php echo $row['OrdState']; ?></td>
    <td><?php echo $row['OrdZip']; ?></td>  
    </tr>
  <?php }?>
</table>

</body>
</html>

Re: Simple list php+Mysql

Posted: 28/09/2012 6:35 pm
by mindphp
ผู้เข้าอบรมโค้ดเวอร์ชั่นเต็ม pm