2013-01-08 2 views
0

많은 사이트를 검색했지만 mysql으로 작성한 쿼리로 링크를 생성하는 방법을 찾을 수 없습니다.mysql에서 쿼리로 링크 만들기

누군가가 coureurname을 클릭하면 다른 페이지로 리디렉션되지만이 쿼리 결과에서 클릭 가능한 링크를 만드는 방법을 원합니다. 아래에 PHP 코드로 쿼리를 게시했습니다.이 작업을 수행하는 방법을 모르기 때문에 여러분이 도와 줄 수 있기를 바랍니다. echo($row[$fieldindex]); 링크를 포함한다고 가정

<html> 
<title> lijstcoureur</title> 
<head> 
<H1> LIJST VAN COUREURS </H1> 
</head> 

<?php 
$con=mysql_connect('localhost','root','****') 
or die ('Kan geen verbinding maken met mySQL server'); 

$db=mysql_select_db('formule1',$con) 
or die ('Kan de database niet selecteren'); 

$selectie=mysql_query("CALL lijstcoureurs()",$con); 
if(!selectie) 
die('Invalid query:'.mysql_error()); 
?> 
<table border =1> 

         <thead> 

           <tr> 
<?php 

             for($fieldindex=0;$fieldindex<mysql_num_fields($selectie);$fieldindex++) 

             { 

               echo '<th>'; 

               echo mysql_field_name($selectie,$fieldindex); 

               echo '</th>'; 

             } 

             ?> 

           </tr> 

         </thead> 

         <tbody> 

           <?php 

           /* 

           Loop alle rijen langs en sla het resultaat op in variable $row */ 

             while($row=mysql_fetch_array($selectie)) 
             { 


               // Begin een nieuwe rij 
               echo('<tr>'); 

               // Loop alle rijen langs en zet de inhoud in de tabel 
               for($fieldindex=0;$fieldindex<mysql_num_fields($selectie);$fieldindex++) 

               { 

                 echo('<td>'); 

                 echo($row[$fieldindex]); 

                 echo('</td>'); 


               } 

               echo('</tr>'); 

             } 

           ?> 

         </tbody> 

       </table> 

     </body> 

</html> 
+1

mysql_ * 함수는 [PHP 5.5에서 더 이상 사용되지 않음] (http://php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated)이 될 것입니다. 나중에 제거 될 예정이므로 새 코드를 작성하는 것은 권장되지 않습니다. 대신 [MySQLi] (http://php.net/manual/en/book.mysqli.php) 또는 [PDO] (http://php.net/manual/en/book.pdo.php) 및 [더 나은 PHP 개발자가 되십시오] (http://jason.pureconcepts.net/2012/08/better-php-developer/). –

답변

0

, 당신은 이런 식으로 작업을 수행 할 수 있습니다

echo "<a href=" . $row[$fieldindex] . ">Anchor text here</a>"; 
0

장소 쿼리 결과를 데이터베이스에서 <a> 태그의 href 속성에. 예를 들어

:

<a href="<?php echo $queryResult; ?>"> My Query Result </a> 
0

나는 당신이 일을하려고 정확히 모르겠어요. 테이블에 링크로 표시 할 URL이 포함되어 있습니까? 그런 다음 <a> 태그에 포장하십시오. 반면에 행을 클릭 할 때 상세보기와 같은 특수 페이지를 표시하려면 해당 기능을 구현해야합니다.

예 :이 특별한 URL에 대한 링크를 만들고 쿼리 문자열에서 ID를 전달합니다

// Assuming $row contains the record's database ID at index 0 
echo '<a href="/some_url/on/your/server?id=' . $row[0] . "'>Anchor text here</a>'; 

. 그런 다음이 URL을 처리하는 또 다른 PHP 스크립트를 작성하면 제공된 ID ($_GET['id'])를 사용하여 문제의 레코드를 검색하고 세부 정보 페이지 나 다른 것을 표시 할 수 있습니다.

PHP 웹 프레임 워크를 살펴 보길 원할 것입니다.이 모든 작업은 지루하고 오류가 발생하기 쉽고 공격에 취약하기 때문입니다. 좋은 프레임 워크는 SQL 인젝션, XSRF 등과 같은 것들에 대한 보호 기능을 가지고 있으며 대부분의 DB 상호 작용을 추상화합니다.

관련 문제