2013-03-03 2 views
0

나는 PHP에 비교적 익숙하다. 내 웹 페이지의 경우 같은 페이지에 여러 페이지를로드해야한다. cwt.html이라는 기본 HTML 페이지가있다. 모든 확인란과 제출 버튼이 있습니다. 제출 버튼을 클릭하면 버튼을 제출하면, 다음 페이지는 .. (cwt.html의) 또한 같은 페이지에로드해야 선택한 체크 박스에 대한 관련PHP의 동일한 페이지에 여러 페이지로드하기

<html> 
<head> 
<title> Conditions We Treat </title> 
</head> 
<body> 
<form id = form1 action = "processing1.php" method = "post"> 
<input type = "checkbox" name = "sickness[]" value = "Nausea">Nausea</input><br/> 
<input type = "checkbox" name = "sickness[]" value = "Constipation">Constipation</input><br/> 
<input type = "checkbox" name = "sickness[]" value = "vomiting">Vomiting</input><br/> 
<div id = "submit1"><input type = "submit" name = "submit" value = "submit"></input></div><br/> 
</form> 
</body> 
</html> 

을 (processing.php 말) 이 웹 페이지에서 클릭 컨트롤이 processing1.php에 머리를해야하지만, 내용이 동일한 페이지

<html> 
<head> 
<title> Conditions We Treat </title> 
</head> 
<body> 
<?php 
echo "hi" 
foreach($_POST['sickness'] as $s) 
{ 
    $con = mysqli_connect("localhost","root","","collofnursing"); 
    //mysql_select_db("collofnursing"); 
    $res = mysqli_query($con,"select * from condwetreat"); 
    while($row = mysqli_fetch_array($res)) 
    { 
     echo $s;?> <br><br><?php 
     } 
} 
?> 
</body> 
</html> 
+1

AJAX에 대해 알아보십시오. – dfsq

+0

비록 JS 지원없이 불필요하게 깨진 웹 사이트를 만들지 않는 것이 예의입니다. – Eevee

답변

0

나는 JQuery와 .load() AJAX를 사용하여 페이지를로드 기능을 사용하는 것이 좋습니다에로드 할 수 있습니다.

Here is the link!

+0

고마워요 :-) 완벽하게 작동했습니다 :-) –

+0

NO PROBLEM! 나는 엄지 손가락 또는 무엇인가 인정할 것이다! :디 – saada

1

당신은 당신이 함수에 onclick 이벤트에 의해 방법을 제출 변경, jQuery를 사용할 수 있습니다 : 다른 사람이 말했다

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script type="text/javascript"> 
function onSubmitForm(){ 
    $.get('page1.php').success(function(html) { 
     $('#page1').html(html); 
    }); 
    $.get('page2.php').success(function(html) { 
     $('#page2').html(html); 
    }); 
} 
</script> 

<div id="page1"></div> 
<div id="page2"></div> 
0

같이, HTML은 div에 니펫을로드 할 수 jQuery를 사용합니다. 이미 완전한 HTML 문서를 가지고 있기 때문에로드하는 텍스트는 완전한 HTML 문서가 아니어야합니다. 시작하려면 div에로드 한 경우 필요한 HTML 만 사용해야합니다.

내가 조언을 제공 할 수 있을지 궁금해하는데 - 질문과 관련이 없습니다! - 유용하다고 생각할 수도 있습니다. 응용 프로그램이 복잡 해짐에 따라 논리와 프레젠테이션 코드를 별도로 유지하는 것이 더 낫다는 것을 알게 될 것입니다. 처음에는 PHP 문서의 시작 부분에 넣고 마지막 부분은 끝에 두는 것입니다. PHP에 대해 더 많이 배우면서, 이것들을 별도의 파일로 가지고 있고 require_once을 사용하여 '템플릿'을로드하는 것이 좋습니다.

이렇게하면 PHP를 작성하는 방법이 로직과 템플릿간에 다른 것을 알 수 있습니다. 템플릿의 경우 각 PHP 문을 단일 PHP 블록에 보관하면 문서가 본질적으로 HTML로 유지됩니다. 이것은 더 깔끔하고 IDE 내부에서 구문 색 지정과 태그 유효성 검사를 활용하는 데 도움이됩니다. 따라서 템플릿을 다음과 같이 작성합니다.

<?php 
// Move this 'logic' code out of the way of your view layer 
// Here, the brace form of loops is preferred 
// Ideally it'd get moved to a different file entirely 
$con = mysqli_connect("localhost","root","","collofnursing"); 
mysql_select_db("collofnursing"); 
$res = mysqli_query($con,"select * from condwetreat"); 

?><html> 
<head> 
    <title> Conditions We Treat </title> 
</head> 
<body> 
    <!-- The PHP 'tags' are now easier to indent --> 
    <!-- So use while/endwhile, foreach/endforeach etc --> 
    Hi 
    <?php while($row = mysqli_fetch_array($res)): ?> 
     <!-- So it's HTML to style stuff, rather than putting 
      HTML tags into PHP echo statements :) --> 
     <p class="symptom"> 
      <?php echo $row['symptom'] ?> 
     </p> 
    <?php endwhile ?> 
</body> 
</html> 
관련 문제