2013-01-14 2 views
0

안녕하세요. 내 블로그에 블로그 게시물의 제목을 만들고 해당 게시물이있는 새 페이지를 클릭 할 수있게하려고합니다. 나는 오류가 있지만 내가 그것을 할 때 : 여기알림 : 정의되지 않은 색인 : post_id

Notice: Undefined index: post_id in C:\wamp\www\blog_test\index.php on line 264 Call Stack #TimeMemoryFunctionLocation 10.0009322712{main}()..\index.php:0 ">Fanboy-ism

라인 (264)입니다 :

<h3><a href="post.php?post_id=<?php echo $row_getDisplay['post_id']; ?>"><?php echo $row_getDisplay['title']; ?></a></h3> 

사람이 나를 혼란, 그것을 해결하는 방법을 어떤 생각을 가지고있다. & & 감사

편집하십시오 : 다음

서버 비헤이비어의 코드가 될 때 :

$maxRows_getArchives = 10; 
$pageNum_getArchives = 0; 
if (isset($_GET['pageNum_getArchives'])) { 
    $pageNum_getArchives = $_GET['pageNum_getArchives']; 
} 
$startRow_getArchives = $pageNum_getArchives * $maxRows_getArchives; 

mysql_select_db($database_blog, $blog); 
$query_getArchives = "SELECT DISTINCT DATE_FORMAT(news.updated, '%M %Y') AS archive, DATE_FORMAT(news.updated, '%Y-%m') AS link FROM news ORDER BY news.updated DESC"; 
$query_limit_getArchives = sprintf("%s LIMIT %d, %d", $query_getArchives, $startRow_getArchives, $maxRows_getArchives); 
$getArchives = mysql_query($query_limit_getArchives, $blog) or die(mysql_error()); 
$row_getArchives = mysql_fetch_assoc($getArchives); 

if (isset($_GET['totalRows_getArchives'])) { 
    $totalRows_getArchives = $_GET['totalRows_getArchives']; 
} else { 
    $all_getArchives = mysql_query($query_getArchives); 
    $totalRows_getArchives = mysql_num_rows($all_getArchives); 
} 
$totalPages_getArchives = ceil($totalRows_getArchives/$maxRows_getArchives)-1; 

mysql_select_db($database_blog, $blog); 
$query_getRecent = "SELECT news.post_id, news.title FROM news ORDER BY news.post_id DESC LIMIT 10"; 
$getRecent = mysql_query($query_getRecent, $blog) or die(mysql_error()); 
$row_getRecent = mysql_fetch_assoc($getRecent); 
$totalRows_getRecent = mysql_num_rows($getRecent); 

$maxRows_getDisplay = 1; 
$pageNum_getDisplay = 0; 
if (isset($_GET['pageNum_getDisplay'])) { 
    $pageNum_getDisplay = $_GET['pageNum_getDisplay']; 
} 
$startRow_getDisplay = $pageNum_getDisplay * $maxRows_getDisplay; 

mysql_select_db($database_blog, $blog); 
$query_getDisplay = "SELECT news.post_id, news.title, news.pre, DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC"; 
$query_limit_getDisplay = sprintf("%s LIMIT %d, %d", $query_getDisplay, $startRow_getDisplay, $maxRows_getDisplay); 
$getDisplay = mysql_query($query_limit_getDisplay, $blog) or die(mysql_error()); 
$row_getDisplay = mysql_fetch_assoc($getDisplay); 

if (isset($_GET['totalRows_getDisplay'])) { 
    $totalRows_getDisplay = $_GET['totalRows_getDisplay']; 
} else { 
    $all_getDisplay = mysql_query($query_getDisplay); 
    $totalRows_getDisplay = mysql_num_rows($all_getDisplay); 
} 
$totalPages_getDisplay = ceil($totalRows_getDisplay/$maxRows_getDisplay)-1; 

mysql_select_db($database_blog, $blog); 
$query_getPosts = "SELECT post_id, title, updated FROM news ORDER BY updated DESC"; 
$getPosts = mysql_query($query_getPosts, $blog) or die(mysql_error()); 
$row_getPosts = mysql_fetch_assoc($getPosts); 
$totalRows_getPosts = mysql_num_rows($getPosts); 

$queryString_getDisplay = ""; 
if (!empty($_SERVER['QUERY_STRING'])) { 
    $params = explode("&", $_SERVER['QUERY_STRING']); 
    $newParams = array(); 
    foreach ($params as $param) { 
    if (stristr($param, "pageNum_getDisplay") == false && 
     stristr($param, "totalRows_getDisplay") == false) { 
     array_push($newParams, $param); 
    } 
    } 
    if (count($newParams) != 0) { 
    $queryString_getDisplay = "&" . htmlentities(implode("&", $newParams)); 
    } 
} 
$queryString_getDisplay = sprintf("&totalRows_getDisplay=%d%s", $totalRows_getDisplay, $queryString_getDisplay); 

$queryString_getArchives = ""; 
if (!empty($_SERVER['QUERY_STRING'])) { 
    $params = explode("&", $_SERVER['QUERY_STRING']); 
    $newParams = array(); 
    foreach ($params as $param) { 
    if (stristr($param, "pageNum_getArchives") == false && 
     stristr($param, "totalRows_getArchives") == false) { 
     array_push($newParams, $param); 
    } 
    } 
    if (count($newParams) != 0) { 
    $queryString_getArchives = "&" . htmlentities(implode("&", $newParams)); 
    } 
} 
$queryString_getArchives = sprintf("&totalRows_getArchives=%d%s", $totalRows_getArchives, $queryString_getArchives); 



$var1_getDisplay2 = "-1"; 
if (isset($_GET['archive'])) { 
    $var1_getDisplay2 = $_GET['archive']; 
    $query_getDisplay = sprintf("SELECT news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y'), news. AS formatted FROM news WHERE DATE_FORMAT(news.updated, '%%Y-%%m') = %s ORDER BY news.updated DESC", GetSQLValueString($var1_getDisplay2, "text")); 
} elseif (isset($_GET['post_id'])) { 
    $var2_getDisplay3 = $_GET['post_id']; 
    $query_getDisplay = sprintf("SELECT news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE news.post_id = %s", GetSQLValueString($var2_getDisplay3, "int")); 
} else { 
    $query_getDisplay = "SELECT news.title, news.blog_entry, DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC LIMIT ".$pageNum_getDisplay.", 5"; 
} 
$getDisplay = mysql_query($query_getDisplay, $blog) or die(mysql_error()); 
$row_getDisplay = mysql_fetch_assoc($getDisplay); 
$totalRows_getDisplay = mysql_num_rows($getDisplay); 
?> 
+0

음 :

여기
echo (isset($row_getDisplay['post_id']) ? $row_getDisplay['post_id'] : ''); 

당신이 당신의 코드로이 어떻게 구현 될 수있다? (정확하게 오류가 나타납니다 :) :) – povilasp

+0

'var_dump ($ row_getDisplay);가 실행될 때 xdebug가 반환하는 것은 무엇입니까? 주제 해제 – Jelmer

+0

: mysql_xxx() 함수가 이제는 사용되지 않습니다. 그것들을 사용하지 말고 새로운 mysqli 또는 PDO 확장으로 전환하는 것이 좋습니다. – SDC

답변

1

나는 모든 대답을 편집 해,

당신은에 post_id를 선택하지 마십시오 검색어 : 검색어를 다음으로 변경하십시오.

if (isset($_GET['archive'])) { 
    $var1_getDisplay2 = $_GET['archive']; 
    $query_getDisplay = sprintf("SELECT news.post_id, news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y'), news. AS formatted FROM news WHERE DATE_FORMAT(news.updated, '%%Y-%%m') = %s ORDER BY news.updated DESC", GetSQLValueString($var1_getDisplay2, "text")); 
} elseif (isset($_GET['post_id'])) { 
    $var2_getDisplay3 = $_GET['post_id']; 
    $query_getDisplay = sprintf("SELECT news.post_id, news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE news.post_id = %s", GetSQLValueString($var2_getDisplay3, "int")); 
} else { 
    $query_getDisplay = "SELECT news.post_id, news.title, news.blog_entry, DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC LIMIT ".$pageNum_getDisplay.", 5"; 
} 

코드에서 추가 참조를 위해 post_id도 선택합니다. 그러면 모든 문제가 해결 될 것입니다. (데이터베이스 모양에 따라 다름)

데이터베이스에서 선택할 수있는 news.post_id가 추가되었습니다. 나는 이것이 해결책이라고 생각한다.

+0

어디 코드에 넣을까요? – Robdogga55

+0

다른 코드 위의 줄. 당신이 태그를 excecute하기 전에로드되어야합니다. (라인 263에서) –

+0

문서를 저장하기 전에 Dreamweaver에서 오류가 발생하는 것 같습니다. – Robdogga55

0

변수가 아직 설정되지 않았다는 것이 이상하게 보입니다.

그러나 변수가 설정되어 있는지 확인하고 그렇지 않은 경우 에코를 확인할 수 있습니다.

예 : $ row_getDisplay [ 'post_id를이'] 이전에 정의되지 않은 것으로 간주 한

<h3><a href="post.php?post_id=<?php echo (isset($row_getDisplay['post_id']) ? $row_getDisplay['post_id'] : ''); ?>"><?php echo (isset($row_getDisplay['title']) ? $row_getDisplay['title'] : ''); ?></a></h3> 
+0

코드에 대한 정보는 어디에 넣을까요? – Robdogga55

+0

답변에 다른 예를 추가했습니다. – CharliePrynn

+0

그것은 오류를 없애 버렸지 만 post_id는 url에 아무 것도 나오지 않습니다. 예를 들어 제목을 클릭하면 "http : //localhost/blog_test/post.php? post_id ="로 바뀝니다. – Robdogga55