2010-04-21 4 views
0

콘텐츠를 사용하여 웹 사이트 홈페이지를 업데이트하는 양식을 만들었지 만 게시글 제목이 특정 게시물 ID에 링크되도록 설정하는 방법을 알고 싶었습니다. 또한 블로그를 읽는 사람에게 올바른 게시물을 보내도록 자세히 알려주는 링크를 추가하고 싶습니다. 링크에게시글 제목을 특정 페이지에 연결 ID

<html> 

<head> 
<title>Blog Name</title> 
</head> 

<body> 

<?php 
mysql_connect ('localhost', 'root', 'root') ; 
mysql_select_db ('tmlblog'); 

$sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5"; 

$result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error()); 
while($row = mysql_fetch_array($result)) { 

    $date = date("l F d Y", $row['timestamp']); 

    $title = stripslashes($row['title']); 
    $entry = stripslashes($row['entry']); 
    $password = $row['password']; 
    $id = $row['id']; 

    if ($password == 1) { 
     echo "<p><strong>" . $title . "</strong></p>"; 

     printf("<p>This is a password protected entry. If you have a password, log in below.</p>"); 

     printf("<form method=\"post\" action=\"post.php?id=%s\"><p><strong><label for=\"username\">Username:</label></strong><br /><input type=\"text\" name=\"username\" id=\"username\" /></p><p><strong><label for=\"pass\">Password:</label></strong><br /><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form>",$id); 
     print "<hr />"; 
    } 
    else { ?> 

     <p><strong><?php echo $title; ?></strong><br /><br /> 
     <?php echo $entry; ?><br /><br /> 
     Posted on <?php echo $date; ?> 

     <hr /></p> 

     <?php 
    } 
} 
    ?> 

</body> 

</html> 
+0

서식을 사용하려면 게시하기 전에 코드 앞에 하나의 탭/4 칸을 추가해야합니다. –

+0

도움 주셔서 감사합니다. Nathan! –

+0

코드에서 echo, printf 및 print를 사용합니다 ... 하나를 선택하여 사용하면 아마 printf()가 아닙니다. 또한 HTML 주위에 작은 따옴표를 사용하면 모든 HTML 인용 부호를 이스케이프하지 않아도됩니다. – TravisO

답변

0

a 태그로 제목을 싸서 게시물 ID를 추가 (또는 다른 독특한 필드), 같은 :

echo "<p><strong><a href=\"?id=". $id . "\">" . $title . "</a></strong></p>"; 

여기

내 PHP 코드 그런 다음 검색어 문자열에서 id 매개 변수를 찾아 누군가가 특정 블로그 게시물을 찾고 있는지 검색 할 수 있습니다.

if (isset($_GET["id"])) { 
    // display blog entry 
} else { 
    // display your blog's front page 
} 
+0

도움 크리스에게 감사드립니다. 정말 감사. 게시물 제목이 마침내 해당 게시물에 연결됩니다! –

관련 문제