<?php
session_start();
include "config.php";
if(isset($_POST['sub'])) {
if(!empty($_POST["column"])) {
$a = $_POST['column']; // column name
} else {
$a ="";
echo "please click on the right input";
}
$r="select '".$a."' , count(*) as '".$a."' from emc_leadgen group by '".$a."' ";
$t=mysql_query($r);
if (!$t)
{
$message = 'ERROR:' . mysql_error();
return $message;
}
else
{
$i = 0;
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
WELCOME <?=$_SESSION['user']?></br>
<title> emc promo 1</title>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
</head>
<body>
<?PHP
echo '<html><body><table><tr>';
while ($i < mysql_num_fields($t))
{
$meta = mysql_fetch_field($t);
echo '<td>' . $meta->name . '</td>';
$i = $i + 1;
}
echo '</tr>';
$i = 0;
while ($row = mysql_fetch_row($t))
{
echo '<tr>';
$count = count($row);
echo $count;
$y = 0;
while ($y < $count)
{
$c_row = current($row);
echo '<td>' . $c_row . '</td>';
echo "</br>";
next($row);
$y = $y + 1;
}
echo '</tr>';
$i = $i + 1;
}
echo '</table></body></html>';
mysql_free_result($t);
}
}{echo "there is no data";}*/
}
?``>
</body>
</html>
// 내 쿼리에서 COUNT를 (를) 사용하고 있습니다. 내 결과에 배열 형식이 표시되지만 데이터베이스에서 고유 한 값이 필요합니다. 데이터베이스에서 값의 어떤을 계산하지 않고 나는이 결과를 필요 아래에 쓴 것처럼 다음을 표시합니다 뉴 델리 = 4 란치 = 2 파리 다밧 = 3 하지만 무엇입니까 도시 = 9 //데이터베이스에서 모든 값을 계산하십시오.
y를 반드시 업데이트하십시오. 매개 변수화 된 쿼리를 사용하여 SQL 주입 공격을 방지하는 코드 http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php –
데이터베이스 구조를보고 정확하게 예상되는 결과를 알고 있으면 좋을 것입니다. – Brewal