2013-03-30 20 views
-1

我想從TABLE中選擇多個列,但腳本在while循環啓動後不工作。我的PHP和HTML代碼是:當選擇多列時,腳本(while循環)停止並且沒有輸出

<table border="0"> 
include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ; 
$sql="select post_title,post_desc,post_date,course,semester,firstname,lastname 
     FROM wbut_forum_posts left join users on post_by = email 
     ORDER BY post_id DESC LIMIT 25"; 
$result = mysqli_query($link,$sql); 

if (!$result) { 
    include_once "wall.html.php"; 
    echo'<tr><td align="center"> OOOOPPPPPSSS!!!SORRY,UNABLE TO DISPLAY LATEST 25 TOPICS</td></tr>'; 
    exit(); 
} 

while ($row = mysqli_fetch_array($result)) { 
    $titles[] = $row['post_title']; 
    $descs[] = $row['post_desc']; 
    $dates[] = $row['post_date']; 
    $courses[] = $row['course']; 
    $semesters[] = $row['semester']; 
    $firstnames[] = $row['firstname']; 
    $lastnames[] = $row['lastname']; 
} 

$cnt=0; 
foreach ($titles as $x) { 
    $title[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

$cnt=0; 
foreach ($firstnames as $x) { 
    $firstname[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

$cnt=0; 
foreach ($lastnames as $x) { 
    $lastname[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

$cnt=0; 
foreach ($descs as $x) { 
    $descs[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

$cnt=0; 
foreach ($dates as $x) { 
    $date[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

$cnt=0; 
foreach ($courses as $x) { 
    $courses[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

$cnt=0; 
foreach ($semesters as $x) { 
    $semester[$cnt]=$x; 
    $cnt=$cnt+1; 
} 

echo'AFTER FOREACHES'; 
for ($i=0;$i<$cnt;$i=$i+1) { 

    echo'<table border="0">'; 
     echo'<tr>'; 
      echo '<td align="left"><span class="style1">'; 
       echo $firstname[$i] . " " . $lastname[$i] ; 
      echo '</span></td>'; 
      echo '<td align="center" colspan="2">RELATED COURSE :'; 
       echo $course[$i]; 
       echo '&nbsp;&nbsp;&nbsp;&nbsp; RELATED SEMESTER:'; 
       echo $semester[$i]; 
      echo '</td>'; 
     echo '</tr>'; 
     echo '<tr>'; 
      echo '<td>&nbsp;</td>'; 
      echo'<td align="left"><span class="style3">'; 
       echo $desc[$i]; 
      echo '</span></td>'; 
      echo'<td valign="baseline">'; 
       echo $date[$i]; 
      echo '</td>'; 
     echo '</tr>'; 
     echo'<tr>'; 
      echo '<td>&nbsp;</td>'; 
      echo '<td align="left" background="reply_bg.gif"><span class="style3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
       echo 'echo the replies here'; 
       echo '</span>'; 
      echo '</td>'; 
      echo'<td>&nbsp;</td>'; 
     echo '</tr>'; 
     echo '<tr>'; 
      echo '<td>&nbsp;</td>'; 
      echo '<form action="reply.html.php" method="post"><td align="left" ><textarea rows="5" cols="40" name="reply" id="reply"></textarea> </td><td valign="baseline"><input type="submit" name="asd" value="REPLY" /><input type="hidden" name="reply" value="reply" /></td></form>'; 
     echo ' </tr>'; 
     echo '</table>';   
    } 
    echo' CLOSING MAIN FOR '; 
?> 
</table> 

注1:未working..I已經在各種地方迴盪。而while循環開始

+0

做'的var_dump($行)' – samayo

+0

沒有得到u.where應該怎麼辦呢 –

+0

你在哪裏與封閉的while循環'}'我無法看到它。你能否向我們提供原始文件? exit()後面的 – 2013-03-30 10:19:59

回答

1
  1. 變量$sql後,哪裏是什麼$result我注意到它究竟是停止?
  2. $result = mysql_query($sql) **or die(mysql_error)** // to give the output error from MySQL if there is any
  3. while之前,使用var_dump($row),或print_r($row)
  4. 如果您遇到空白頁面或無錯誤報告,請在腳本開始處使用error_reporting(E_ALL);

編輯:對不起,您正在使用MySQLi。使用$mysqli->error

+0

iagain同樣的錯誤,而複製在這裏..看最新的編輯..我寫了$結果 –

+0

考慮輸出由MySQLi產生的錯誤。你可能有空的一組行,所以你沒有得到任何結果。或語法錯誤http://www.nusphere.com/kb/phpmanual/function.mysqli-error.htm – Mido

+0

相同的結果沒有輸出 –

0

您的代碼第一行沒有開放的PHP標籤。 它應該是:

<table border="0"><?