2011-03-02 4 views
0

포럼의 내용을 보는 데 사용하는 간단한 PHP 코드입니다. 문제는 내 노트북 ​​중 하나에서 정상적으로 작동하지만 초에 출력이 표시되지 않는다는 것입니다.이 PHP 코드의 문제점은 무엇입니까?

// Connect to server and select databse. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

$sql="SELECT * FROM $tbl_name ORDER BY id DESC"; 
// OREDER BY id DESC is order result by descending 
$result=mysql_query($sql); 
?> 
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> 
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td> 
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> 
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> 
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> 
</tr> 

<?php 
while($rows=mysql_fetch_array($result)){ // Start looping table row 
?> 
<tr> 
<td bgcolor="#E6E6E6"><? echo $rows['id']; ?></td> 
<td bgcolor="#E6E6E6"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td> 
<td align="center" bgcolor="#E6E6E6"><? echo $rows['view']; ?></td> 
<td align="center" bgcolor="#E6E6E6"><? echo $rows['reply']; ?></td> 
<td align="center" bgcolor="#E6E6E6"><? echo $rows['datetime']; ?></td> 
</tr> 

나는 그 밖의 모든 것을 검사했다. 데이터가 데이터베이스에 있지만 포럼에 표시되지 않습니다. 아무도 이걸 도와 줄 수 없나요? 운영 체제 : win7

+0

모든 코드와 데이터베이스 구조를 게시하십시오. –

+0

'$ tbl_name '이 정의 된 곳이 보이지 않습니다. 랩톱에서이 코드를 실행하고 있습니까 아니면 다른 곳에 호스팅되어 있습니까? –

+1

짧은 태그가 비활성화되었을 수도 있습니다. 변경 로 시작하고 smottt

답변

2

디버깅을 배우는 데 걸리는 시간. MySQL을위한 http://www.ibm.com/developerworks/library/os-debug/

는 쿼리이 방법을 실행하는 것이 매우 편리합니다 :

$result=mysql_query($sql) or trigger_error(mysql_error()." ".$sql); 

을하고 모든 오류가 발생 볼 수 있는지 확인

시작하기에 좋은 곳. 당신이 빠른 수정으로 스크립트

ini_set('display_errors',1); 
error_reporting(E_ALL); 

의 상단에 다음 라인을 추가 할 수 없지만 생산 상태에 대한 display_errors 값이 0

변경해야하는 경우 또한 좋은 방법입니다 브라우저에서 렌더링 된 페이지를 보는 대신 HTML 소스를 확인하십시오. 짧은 태그에 문제가 있는지 여부를 알려줍니다. 문제를 해결하기 전에 문제가 있는지 항상 확인하는 것이 좋습니다.

2

당신이

<?php echo $rows['id']; ?> 대신 <? echo $rows['id']; ?>

짧은 태그를 사용한다이 비활성화 될 수 있습니다.

+0

고마워요. 끝났다. – shona

관련 문제