2012-10-11 2 views
1

사용자가 드롭 다운 메뉴에서 값을 선택하고 데이터베이스에서 정보를 얻을 수있는 웹 사이트를 만들었습니다. 아약스를 사용하여 데이터베이스에 요청을 보냈습니다. 요청을 보내면 페이지가 새로 고쳐지지 않습니다. 여기 JQuery와 함수의 일부는 다음과 같습니다링크를 클릭하면 PHP 쿼리의 where 절에서 링크의 이름을 가져 옵니까?

 $.ajax({ 
     type:'POST', 
     url:'activities_code.php', 
     data: {datastr:datastr, datastr1:datastr1}, 
     success:function(response){ 

     $("#msg").html(response);       
      }});}); // there are other functions before.. 

결과는 웹 페이지의 주요 컨테이너에 나타납니다. 제목과 일부 텍스트로 구성됩니다. 그런 식으로 제목을 되풀이하여 링크입니다. 또한 각 요소에 ID와 클래스를 제공하므로 나중에 호출 할 수 있습니다. 내가 지금하려고하는 것은

echo "<table id=\"container\">"; 
$num_results = 0; 
while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    // Here the columns of title and information are printed 
    echo "<tr><td>"; 
    echo "<a href='test.php' name=\"fd\" id=\"t".$t."\" target=\"_new\" class='pickanchor' onClick=\"test()\">".$row['title']."</a>"; 
    echo "<br>"; 
    echo $row['PK']; 
    echo "</td></tr>"; 

    echo "<tr><td>"; 
    echo $row['Information']; 
    echo "</td></tr>"; 
} 

: 나는 (링크 인) 제목을 클릭하면 새 페이지를 열 수있는 PHP 스크립트 쿼리와 쇼를 실행 한 다음 해당 코드는 자세한 내용은 :

 $query = "SELECT title,Information from activities where title='?????'"; 
:

 <?php 
    include('connect.php'); 


    $query = "SELECT title,Information from activities where title='?????'"; 

$result = mysqli_query($dbcon, $query) or die('no available data'); 
echo "<table>"; 
$num_results = 0; 
while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    // Here the columns of title and information are printed 
    echo "<tr><td>"; 
    echo "<a href='test.php' id=\"t\".$t target=\"_new\">".$row['title']." </a>"; 
    echo "</td></tr>"; 

    echo "<tr><td>"; 

    echo $row['Information']; 

    echo "</td></tr>"; 
    // Here I sum up the number of the results 
    $num_results=$num_results+1;   
} 
    ?> 

나는, where 절에, 내 쿼리에 넣을 수있는 방법을 찾기 위해 내가 선택한 타이틀의 이름을하려합니다 : 여기 내가 가진 무엇

도움이 되셨습니까? 많이 감사하겠습니다. 모든 것이 명확한 지 또는 어떤 점을 명확하게 설명하지 않았다면 알려주십시오. 감사합니다. . D.

+0

가 $ .post와 함께 온 클릭 기능을 수행 (? URL 제목 = $ ('. 제목') 발().) – JonathanRomer

답변

1

$_GET 전역 변수 및 URL 매개 변수를 사용하여 이라는 제목을 얻을 수 있습니다. 이 줄을 변경해보십시오 :

echo "<a href='test.php' name=\"fd\" id=\"t".$t."\" target=\"_new\" class='pickanchor' onClick=\"test()\">".$row['title']."</a>"; 

echo "<a href='test.php?title={$row['title']}' name=\"fd\" id=\"t".$t."\" target=\"_new\" class='pickanchor' onClick=\"test()\">".$row['title']."</a>"; 

에 다음이 코드로 타이틀을 얻을 수 있습니다 :

$title = $_GET['title']; 

가 먼저 값을 소독해야합니다. 이게 당신을 도울 수 있기를 바랍니다.

링크 :

PHP $_GET

+0

고마워요! 그것은 완벽하게 작동합니다! 나는 php에서 새롭고 소독으로 무엇을 의미하는지 확신 할 수 없다. 나에게 힌트를 줄 수 있니? 다시 한번 감사드립니다. – user1919

관련 문제