Skip to content

Instantly share code, notes, and snippets.

@tranphuoctien
Created October 18, 2018 00:37
Show Gist options
  • Save tranphuoctien/a5d611a0a45b6b338e14f9df47874c1c to your computer and use it in GitHub Desktop.
Save tranphuoctien/a5d611a0a45b6b338e14f9df47874c1c to your computer and use it in GitHub Desktop.
My code in 5 years ago
<?php
$tpt_demo="SELECT * FROM `news`"; // Lệnh select dữ liệu bảng news
$tpt_run_sql=mysql_query($tpt_demo); // Chạy câu lệnh
$tpt_get_columns=mysql_query("SHOW COLUMNS FROM `news`"); // chạy lệnh lấy columns
$tpt_array= array(); // khai báo mãng ( k làm cũng đc =))
$tpt_columns= array();// khai báo mãng ( cái này k làm cũng đc =)))
while ($row1 = mysql_fetch_array($tpt_get_columns)) {
$tpt_columns[]=$row1['Field']; // đưa dữ liệu vào mảng,có nhìu cách,mình chọn cách này,tại quen rồi. =))
}
while($row=mysql_fetch_array($tpt_run_sql)){
$tpt_array[]=$row; // tương tự cũng đưa dữ liệu vào mảng.
}
foreach ($tpt_array as $key =>$value){
foreach ($tpt_columns as $key1){
echo "Key Index:<b> $key1 </b><br>";
echo $tpt_array[$key][$key1]."<br>";
//echo $key1."<br>";
// Hai foreach lồng để lấy giá trị cần để lấy.
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment