Monday, June 25, 2012

PHP, Extract data array in MySQL



Below is the step to extract data array of MySQL in PHP
1) Define an array:
 $modules_payment = Array();
2)  Example Query
 $sql = 'SELECT * FROM edu_payments WHERE member_id ='.$_SESSION['member_id'];
  $result = mysql_query($sql, $db);
   while($row = mysql_fetch_assoc($result)){
      // Assign  MySQL result to a multi-dimensional array
       $modules_payment[] = $row;
    } 
3) Extract data from the multi-dimensional  array
foreach($modules_payment as $my_payment){
       foreach($my_payment as $key=>$payment) echo  $payment.'<br />';
}

No comments:

Post a Comment