PHP에 익숙하지 않고 약간의 문제가 발생하여 도움이 될지 궁금해졌습니다. 데이터베이스에서 찾은 배열 이름에 문제가 있습니다. 이름 배열을 사용할 때 올바르게 처리됩니다. 내가 같은 이름의 파일을 읽으려고 할 때 마지막 이름 만 표시됩니다. 내 질문에 어떻게 파일 배열에 대한 모든 이름을 표시 할 수 있습니까?파일을 배열에로드하는 중
아래의 예 및 코드를 참조하십시오. 시간 내 줘서 고마워.
//This works -- Sample 1
$x = array("joe", "paul", "tom");
//This does not -- Sample 2
$x = file("name.txt"); //Same names from the array above are in this file
다음은 전체 코드입니다.
<html>
<head>
<title>Name Check</title>
</head>
<body>
<?php
$con = mysql_connect("localhost", "xxxxxxxx", "xxxxxxxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxxx", $con);
// $x=array("joe", "paul", "tom"); //displays all names correctly in Sample 1 below
$x = file("name.txt"); // only displays the last name in the file. Sample 2 below
foreach ($x as $test) {
$result = mysql_query("SELECT * FROM categories WHERE Name='$test' Limit 0, 1");
while ($row = mysql_fetch_array($result)) {
echo $row['Name'];
echo " " . $row['Sport'];
echo "<br />";
}
}
?>
</body>
</html>
샘플 1 출력
joe basketball
paul basketball
tom baseball
샘플 2 출력 여기서
tom baseball
는 내용물 인 요청 된 name.txt 중 하나입니다. 감사! 마지막 하나가 부족 각 라인의 끝에 개행 문자에
joe
paul
tom
당신은 샘플 파일의 내용을 제공 할 수 있을까요? –
파일의 형식을 게시하십시오. –