안녕하세요 안드로이드에서 php로 mysql 데이터 검색하는걸 만들고 있는데
php에서 뭔가 좀 안되는거 같아서 질문 드립니다.
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$link=mysqli_connect("localhost","root","Manager1", "bus" );
if (!$link)
{
echo "MySQL 접속 에러 : ";
echo mysqli_connect_error();
exit();
}
mysqli_set_charset($link,"utf8");
$country=isset($_POST['country']) ? $_POST['country'] : '';
$android = strpos($_SERVER['HTTP_USER_AGENT'], "Android");
if ($country !="" ){
$sql="select * from businfo where Number='$country'";
$result=mysqli_query($link,$sql);
$data = array();
if($result){
$row_count = mysqli_num_rows($result);
if ( 0 == $row_count ){
array_push($data,
array('Number'=>'N',
'Stop'=>$country)
);
if (!$android) {
echo "'";
echo $country;
echo "'은 찾을 수 없습니다.";
echo "<pre>";
print_r($data);
echo '</pre>';
}else
{
header('Content-Type: application/json; charset=utf8');
$json = json_encode(array("webnautes"=>$data), JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
echo $json;
}
}
else{
while($row=mysqli_fetch_array($result)){
array_push($data,
array(
'Number'=>$row["Number"],
'Stop'=>$row["Stop"]
));
}
if (!$android) {
echo "<pre>";
print_r($data);
echo '</pre>';
}else
{
header('Content-Type: application/json; charset=utf8');
$json = json_encode(array("webnautes"=>$data), JSON_PRETTY_PRINT+JSON_UNESCAPED_UNICODE);
echo $json;
}
}
mysqli_free_result($result);
}
else{
echo "SQL문 처리중 에러 발생 : ";
echo mysqli_error($link);
}
}
else {
echo "검색할 버스를 입력하세요 ";
}
mysqli_close($link);
?>
<?php
$android = strpos($_SERVER['HTTP_USER_AGENT'], "Android");
if (!$android){
?>
<html>
<body>
<form action="<?php $_PHP_SELF ?>" method="POST">
버스 번호: <input type = "text" Number = "country" />
<input type = "submit" />
</form>
</body>
</html>
<?php
}
?>
구글링으로 mysql에 있는 데이터 검색하는 소스코드에서 조금조금씩 바꿔서 하고있습니다.
localhost/php 로 열어서 하는중에 검색 창은 뜨는데 검색을 해도
mysql에 저장되어있는 데이터가 불러와 지지 않습니다.
php는 처음 다뤄봐서 어디에 어떻게 손을 대야 할지 잘 모르겠습니다
(안드로이드 스튜디오랑 mysql 연동도 완료됬고 소스코드를 통해서 데이터 검색이나 추가 되는것도 확인 했습니다.)